diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-08-04 17:12:56 +0200 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-08-04 17:12:56 +0200 |
commit | dd6cf808d69eaa52f7642def5f6f94500ee9bc79 (patch) | |
tree | 22a5f40c1d398af393be3aacb576b56d082fc03d /lib/user.h | |
parent | 3f09b1b3e1edcdb7b21d7f3e4f4764f0bd084f30 (diff) | |
download | libquotient-dd6cf808d69eaa52f7642def5f6f94500ee9bc79.tar.gz libquotient-dd6cf808d69eaa52f7642def5f6f94500ee9bc79.zip |
User: optimise names/avatars storing and updating
The current mechanism relied on a complicated and fragile machinery
around setNameForRoom() and setAvatarForRoom() that maintained the
"most used" entity for a given user along with "other" ones. Given that
per-room avatars are pretty rare in Matrix, it's also been inefficient
as kitsune-benchmark-set_ForRoom branch shows. The new mechanism stores
the "default" (as per user profile) name and avatar and maintains
a singleton map of avatar objects across all users. Per-user profile
only (normally) exists for the local user so there's yet another
inefficiency that will be fixed further down the road by introducing
a separate user profile class.
Diffstat (limited to 'lib/user.h')
-rw-r--r-- | lib/user.h | 44 |
1 files changed, 15 insertions, 29 deletions
@@ -33,13 +33,12 @@ class User : public QObject { Q_PROPERTY(bool isGuest READ isGuest CONSTANT) Q_PROPERTY(int hue READ hue CONSTANT) Q_PROPERTY(qreal hueF READ hueF CONSTANT) - Q_PROPERTY(QString name READ name NOTIFY nameChanged) - Q_PROPERTY(QString displayName READ displayname NOTIFY nameChanged STORED false) - Q_PROPERTY(QString fullName READ fullName NOTIFY nameChanged STORED false) - Q_PROPERTY(QString bridgeName READ bridged NOTIFY nameChanged STORED false) - Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY avatarChanged - STORED false) - Q_PROPERTY(QUrl avatarUrl READ avatarUrl NOTIFY avatarChanged) + Q_PROPERTY(QString name READ name NOTIFY defaultNameChanged) + Q_PROPERTY(QString displayName READ displayname NOTIFY defaultNameChanged STORED false) + Q_PROPERTY(QString fullName READ fullName NOTIFY defaultNameChanged STORED false) + Q_PROPERTY(QString bridgeName READ bridged NOTIFY defaultNameChanged STORED false) + Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY defaultAvatarChanged STORED false) + Q_PROPERTY(QUrl avatarUrl READ avatarUrl NOTIFY defaultAvatarChanged) public: User(QString userId, Connection* connection); ~User() override; @@ -123,20 +122,14 @@ public: QString avatarMediaId(const Room* room = nullptr) const; QUrl avatarUrl(const Room* room = nullptr) const; - /// This method is for internal use and should not be called - /// from client code - // FIXME: Move it away to private - void processEvent(const RoomMemberEvent& event, const Room* r, - bool firstMention); - public slots: - /** Set a new name in the global user profile */ + /// Set a new name in the global user profile void rename(const QString& newName); - /** Set a new name for the user in one room */ + /// Set a new name for the user in one room void rename(const QString& newName, const Room* r); - /** Upload the file and use it as an avatar */ + /// Upload the file and use it as an avatar bool setAvatar(const QString& fileName); - /** Upload contents of the QIODevice and set that as an avatar */ + /// Upload contents of the QIODevice and set that as an avatar bool setAvatar(QIODevice* source); /// Create or find a direct chat with this user /*! The resulting chat is returned asynchronously via @@ -151,21 +144,14 @@ public slots: bool isIgnored() const; signals: - void nameAboutToChange(QString newName, QString oldName, - const Quotient::Room* roomContext); - void nameChanged(QString newName, QString oldName, - const Quotient::Room* roomContext); - void avatarChanged(Quotient::User* user, const Quotient::Room* roomContext); - -private slots: - void updateName(const QString& newName, const Room* room = nullptr); - void updateName(const QString& newName, const QString& oldName, - const Room* room = nullptr); - void updateAvatarUrl(const QUrl& newUrl, const QUrl& oldUrl, - const Room* room = nullptr); + void defaultNameChanged(); + void defaultAvatarChanged(); private: class Private; QScopedPointer<Private> d; + + template <typename SourceT> + bool doSetAvatar(SourceT&& source); }; } // namespace Quotient |