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:
@@ -321,6 +321,7 @@ Kirigami.ScrollablePage {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
text: model.connection.localUserId
|
text: model.connection.localUserId
|
||||||
|
subtitle: model.connection.localUser.accountLabel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,6 +151,11 @@ Kirigami.ScrollablePage {
|
|||||||
text: userEditSheet.connection ? userEditSheet.connection.localUser.displayName : ""
|
text: userEditSheet.connection ? userEditSheet.connection.localUser.displayName : ""
|
||||||
Kirigami.FormData.label: i18n("Name:")
|
Kirigami.FormData.label: i18n("Name:")
|
||||||
}
|
}
|
||||||
|
Controls.TextField {
|
||||||
|
id: accountLabel
|
||||||
|
text: userEditSheet.connection ? userEditSheet.connection.localUser.accountLabel : ""
|
||||||
|
Kirigami.FormData.label: i18n("Label:")
|
||||||
|
}
|
||||||
Controls.TextField {
|
Controls.TextField {
|
||||||
id: currentPassword
|
id: currentPassword
|
||||||
Kirigami.FormData.label: i18n("Current Password:")
|
Kirigami.FormData.label: i18n("Current Password:")
|
||||||
@@ -179,6 +184,8 @@ Kirigami.ScrollablePage {
|
|||||||
showPassiveNotification("The Avatar could not be set")
|
showPassiveNotification("The Avatar could not be set")
|
||||||
if(userEditSheet.connection.localUser.displayName !== name.text)
|
if(userEditSheet.connection.localUser.displayName !== name.text)
|
||||||
userEditSheet.connection.localUser.rename(name.text)
|
userEditSheet.connection.localUser.rename(name.text)
|
||||||
|
if(userEditSheet.connection.localUser.accountLabel !== accountLabel.text)
|
||||||
|
userEditSheet.connection.localUser.setAccountLabel(accountLabel.text)
|
||||||
if(currentPassword.text !== "" && newPassword.text !== "" && confirmPassword.text !== "") {
|
if(currentPassword.text !== "" && newPassword.text !== "" && confirmPassword.text !== "") {
|
||||||
if(newPassword.text === confirmPassword.text) {
|
if(newPassword.text === confirmPassword.text) {
|
||||||
Controller.changePassword(userEditSheet.connection, currentPassword.text, newPassword.text)
|
Controller.changePassword(userEditSheet.connection, currentPassword.text, newPassword.text)
|
||||||
|
|||||||
@@ -4,13 +4,23 @@
|
|||||||
#include "neochatuser.h"
|
#include "neochatuser.h"
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
#include <QJsonObject>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
|
||||||
|
#include <connection.h>
|
||||||
|
|
||||||
NeoChatUser::NeoChatUser(QString userId, Connection *connection)
|
NeoChatUser::NeoChatUser(QString userId, Connection *connection)
|
||||||
: User(std::move(userId), connection)
|
: User(std::move(userId), connection)
|
||||||
{
|
{
|
||||||
connect(static_cast<QGuiApplication *>(QGuiApplication::instance()), &QGuiApplication::paletteChanged, this, &NeoChatUser::polishColor);
|
connect(static_cast<QGuiApplication *>(QGuiApplication::instance()), &QGuiApplication::paletteChanged, this, &NeoChatUser::polishColor);
|
||||||
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()
|
QColor NeoChatUser::color()
|
||||||
@@ -34,3 +44,17 @@ void NeoChatUser::polishColor()
|
|||||||
// https://github.com/quotient-im/libQuotient/wiki/User-color-coding-standard-draft-proposal
|
// https://github.com/quotient-im/libQuotient/wiki/User-color-coding-standard-draft-proposal
|
||||||
setColor(QColor::fromHslF(hueF(), 1, -0.7 * lightness + 0.9, 1));
|
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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ class NeoChatUser : public User
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||||
|
// Only valid for the local user
|
||||||
|
Q_PROPERTY(QString accountLabel READ accountLabel WRITE setAccountLabel NOTIFY accountLabelChanged)
|
||||||
public:
|
public:
|
||||||
NeoChatUser(QString userId, Connection *connection);
|
NeoChatUser(QString userId, Connection *connection);
|
||||||
|
|
||||||
@@ -20,8 +22,13 @@ public Q_SLOTS:
|
|||||||
QColor color();
|
QColor color();
|
||||||
void setColor(const QColor &color);
|
void setColor(const QColor &color);
|
||||||
|
|
||||||
|
// Only valid for the local user
|
||||||
|
QString accountLabel() const;
|
||||||
|
void setAccountLabel(const QString &accountLabel);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void colorChanged(QColor _t1);
|
void colorChanged(QColor _t1);
|
||||||
|
void accountLabelChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QColor m_color;
|
QColor m_color;
|
||||||
|
|||||||
Reference in New Issue
Block a user