Implement adding labels for account
This gives the user the ability to label different account (e.g. "work", "private") and shows this label in the account switcher. Showing the label in more places will be done in future MRs. The label is stored in the user's account data and thus transfers automatically to other instances of neochat
This commit is contained in:
@@ -4,13 +4,23 @@
|
||||
#include "neochatuser.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QJsonObject>
|
||||
#include <QPalette>
|
||||
|
||||
#include <connection.h>
|
||||
|
||||
NeoChatUser::NeoChatUser(QString userId, Connection *connection)
|
||||
: User(std::move(userId), connection)
|
||||
{
|
||||
connect(static_cast<QGuiApplication *>(QGuiApplication::instance()), &QGuiApplication::paletteChanged, this, &NeoChatUser::polishColor);
|
||||
polishColor();
|
||||
if (connection->userId() == id()) {
|
||||
connect(connection, &Connection::accountDataChanged, this, [this](QString type) {
|
||||
if (type == QLatin1String("org.kde.neochat.account_label")) {
|
||||
Q_EMIT accountLabelChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
QColor NeoChatUser::color()
|
||||
@@ -34,3 +44,17 @@ void NeoChatUser::polishColor()
|
||||
// https://github.com/quotient-im/libQuotient/wiki/User-color-coding-standard-draft-proposal
|
||||
setColor(QColor::fromHslF(hueF(), 1, -0.7 * lightness + 0.9, 1));
|
||||
}
|
||||
|
||||
void NeoChatUser::setAccountLabel(const QString &accountLabel)
|
||||
{
|
||||
Q_ASSERT(connection()->user()->id() == id());
|
||||
QJsonObject json;
|
||||
json["account_label"] = accountLabel;
|
||||
connection()->setAccountData("org.kde.neochat.account_label", json);
|
||||
}
|
||||
|
||||
QString NeoChatUser::accountLabel() const
|
||||
{
|
||||
Q_ASSERT(connection()->user()->id() == id());
|
||||
return connection()->accountDataJson("org.kde.neochat.account_label")["account_label"].toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user