From c94ad527ed94a4c1ca368dc8c8c59e490b907649 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 17 Nov 2018 19:50:34 +0900 Subject: User::isIgnored() --- lib/user.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index 17f5625f..0023b44a 100644 --- a/lib/user.h +++ b/lib/user.h @@ -125,6 +125,8 @@ namespace QMatrixClient void ignore(); /** Remove the user from the ignore list */ void unmarkIgnore(); + /** Check whether the user is in ignore list */ + bool isIgnored() const; signals: void nameAboutToChange(QString newName, QString oldName, -- cgit v1.2.3 From aacc4bcb4a487871daae6717f77605aaba444341 Mon Sep 17 00:00:00 2001 From: Marc Deop Date: Sat, 2 Mar 2019 12:26:57 +0100 Subject: style: apply .clang-format to all .cpp and .h files --- lib/user.h | 227 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 115 insertions(+), 112 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index 0023b44a..c174314e 100644 --- a/lib/user.h +++ b/lib/user.h @@ -13,138 +13,141 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #pragma once -#include -#include #include "avatar.h" +#include +#include -namespace QMatrixClient -{ +namespace QMatrixClient { class Connection; class Room; class RoomMemberEvent; - class User: public QObject + class User : public QObject { - Q_OBJECT - Q_PROPERTY(QString id READ id CONSTANT) - Q_PROPERTY(bool isGuest READ isGuest 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_OBJECT + Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(bool isGuest READ isGuest 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) public: - User(QString userId, Connection* connection); - ~User() override; - - Connection* connection() const; - - /** Get unique stable user id - * User id is generated by the server and is not changed ever. - */ - QString id() const; - - /** Get the name chosen by the user - * This may be empty if the user didn't choose the name or cleared - * it. If the user is bridged, the bridge postfix (such as '(IRC)') - * is stripped out. No disambiguation for the room is done. - * \sa displayName, rawName - */ - QString name(const Room* room = nullptr) const; - - /** Get the user name along with the bridge postfix - * This function is similar to name() but appends the bridge postfix - * (such as '(IRC)') to the user name. No disambiguation is done. - * \sa name, displayName - */ - QString rawName(const Room* room = nullptr) const; - - /** Get the displayed user name - * When \p room is null, this method returns result of name() if - * the name is non-empty; otherwise it returns user id. - * When \p room is non-null, this call is equivalent to - * Room::roomMembername invocation for the user (i.e. the user's - * disambiguated room-specific name is returned). - * \sa name, id, fullName, Room::roomMembername - */ - QString displayname(const Room* room = nullptr) const; - - /** Get user name and id in one string - * The constructed string follows the format 'name (id)' - * which the spec recommends for users disambiguation in - * a room context and in other places. - * \sa displayName, Room::roomMembername - */ - QString fullName(const Room* room = nullptr) const; - - /** - * Returns the name of bridge the user is connected from or empty. - */ - QString bridged() const; - - /** Whether the user is a guest - * As of now, the function relies on the convention used in Synapse - * that guests and only guests have all-numeric IDs. This may or - * may not work with non-Synapse servers. - */ - bool isGuest() const; - - const Avatar& avatarObject(const Room* room = nullptr) const; - Q_INVOKABLE QImage avatar(int dimension, const Room* room = nullptr); - Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight, - const Room* room = nullptr); - QImage avatar(int width, int height, const Room* room, - const Avatar::get_callback_t& callback); - - QString avatarMediaId(const Room* room = nullptr) const; - QUrl avatarUrl(const Room* room = nullptr) const; - - void processEvent(const RoomMemberEvent& event, const Room* r); + User(QString userId, Connection* connection); + ~User() override; + + Connection* connection() const; + + /** Get unique stable user id + * User id is generated by the server and is not changed ever. + */ + QString id() const; + + /** Get the name chosen by the user + * This may be empty if the user didn't choose the name or cleared + * it. If the user is bridged, the bridge postfix (such as '(IRC)') + * is stripped out. No disambiguation for the room is done. + * \sa displayName, rawName + */ + QString name(const Room* room = nullptr) const; + + /** Get the user name along with the bridge postfix + * This function is similar to name() but appends the bridge postfix + * (such as '(IRC)') to the user name. No disambiguation is done. + * \sa name, displayName + */ + QString rawName(const Room* room = nullptr) const; + + /** Get the displayed user name + * When \p room is null, this method returns result of name() if + * the name is non-empty; otherwise it returns user id. + * When \p room is non-null, this call is equivalent to + * Room::roomMembername invocation for the user (i.e. the user's + * disambiguated room-specific name is returned). + * \sa name, id, fullName, Room::roomMembername + */ + QString displayname(const Room* room = nullptr) const; + + /** Get user name and id in one string + * The constructed string follows the format 'name (id)' + * which the spec recommends for users disambiguation in + * a room context and in other places. + * \sa displayName, Room::roomMembername + */ + QString fullName(const Room* room = nullptr) const; + + /** + * Returns the name of bridge the user is connected from or empty. + */ + QString bridged() const; + + /** Whether the user is a guest + * As of now, the function relies on the convention used in Synapse + * that guests and only guests have all-numeric IDs. This may or + * may not work with non-Synapse servers. + */ + bool isGuest() const; + + const Avatar& avatarObject(const Room* room = nullptr) const; + Q_INVOKABLE QImage avatar(int dimension, const Room* room = nullptr); + Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight, + const Room* room = nullptr); + QImage avatar(int width, int height, const Room* room, + const Avatar::get_callback_t& callback); + + QString avatarMediaId(const Room* room = nullptr) const; + QUrl avatarUrl(const Room* room = nullptr) const; + + void processEvent(const RoomMemberEvent& event, const Room* r); public slots: - /** Set a new name in the global user profile */ - void rename(const QString& newName); - /** 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 */ - bool setAvatar(const QString& fileName); - /** 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 - * Connection::directChatAvailable() - */ - void requestDirectChat(); - /** Add the user to the ignore list */ - void ignore(); - /** Remove the user from the ignore list */ - void unmarkIgnore(); - /** Check whether the user is in ignore list */ - bool isIgnored() const; + /** Set a new name in the global user profile */ + void rename(const QString& newName); + /** 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 */ + bool setAvatar(const QString& fileName); + /** 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 + * Connection::directChatAvailable() + */ + void requestDirectChat(); + /** Add the user to the ignore list */ + void ignore(); + /** Remove the user from the ignore list */ + void unmarkIgnore(); + /** Check whether the user is in ignore list */ + bool isIgnored() const; signals: - void nameAboutToChange(QString newName, QString oldName, - const Room* roomContext); - void nameChanged(QString newName, QString oldName, - const Room* roomContext); - void avatarChanged(User* user, const Room* roomContext); + void nameAboutToChange(QString newName, QString oldName, + const Room* roomContext); + void nameChanged(QString newName, QString oldName, + const Room* roomContext); + void avatarChanged(User* user, const 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 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); private: - class Private; - QScopedPointer d; + class Private; + QScopedPointer d; }; } Q_DECLARE_METATYPE(QMatrixClient::User*) -- cgit v1.2.3 From a28892ca3b40a32556ee7615116c322f6b2a4ae5 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 29 Mar 2019 13:26:36 +0900 Subject: Room::processStateEvent, User: take the previous membership state from oldStateEvent memberJoinState() just happens to return the not-yet-updated state, making its use around state changes very sensitive to moving things around. The event's own prevContent is unsigned, therefore untrusted. --- lib/user.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index 0023b44a..7c9ed55f 100644 --- a/lib/user.h +++ b/lib/user.h @@ -105,7 +105,11 @@ namespace QMatrixClient QString avatarMediaId(const Room* room = nullptr) const; QUrl avatarUrl(const Room* room = nullptr) const; - void processEvent(const RoomMemberEvent& event, const Room* r); + /// This method is for internal use and should not be called + /// from client code + // FIXME: Move it away to private in lib 0.6 + void processEvent(const RoomMemberEvent& event, const Room* r, + bool firstMention); public slots: /** Set a new name in the global user profile */ -- cgit v1.2.3 From 74fa9bc64128d88939259ccb2ba4dca51571559a Mon Sep 17 00:00:00 2001 From: Alexey Andreyev Date: Wed, 6 Mar 2019 22:13:05 +0300 Subject: Provide a colour code for the user Contributes to #296 --- lib/user.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index 0023b44a..af1abfa2 100644 --- a/lib/user.h +++ b/lib/user.h @@ -33,6 +33,8 @@ namespace QMatrixClient Q_OBJECT Q_PROPERTY(QString id READ id CONSTANT) 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) @@ -95,6 +97,15 @@ namespace QMatrixClient */ bool isGuest() const; + /** Hue color component of this user based on id. + * The implementation is based on XEP-0392: + * https://xmpp.org/extensions/xep-0392.html + * Naming and ranges are the same as QColor's hue methods: + * https://doc.qt.io/qt-5/qcolor.html#integer-vs-floating-point-precision + */ + int hue() const; + qreal hueF() const; + const Avatar& avatarObject(const Room* room = nullptr) const; Q_INVOKABLE QImage avatar(int dimension, const Room* room = nullptr); Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight, -- cgit v1.2.3 From c05ade838f0fce81f2bbe80a3295618a8a26ff52 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 2 Aug 2019 19:59:40 +0900 Subject: Apply the new brace wrapping to source files --- lib/user.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index f4d7cff3..779efb34 100644 --- a/lib/user.h +++ b/lib/user.h @@ -23,14 +23,12 @@ #include #include -namespace QMatrixClient -{ +namespace QMatrixClient { class Connection; class Room; class RoomMemberEvent; -class User : public QObject -{ +class User : public QObject { Q_OBJECT Q_PROPERTY(QString id READ id CONSTANT) Q_PROPERTY(bool isGuest READ isGuest CONSTANT) -- cgit v1.2.3 From 27ca32a1e5a56e09b9cc1d94224d2831004dcf3d Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 7 Jul 2019 19:32:34 +0900 Subject: Namespace: QMatrixClient -> Quotient (with back comp alias) --- lib/user.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index 779efb34..c9e3dbc1 100644 --- a/lib/user.h +++ b/lib/user.h @@ -23,7 +23,7 @@ #include #include -namespace QMatrixClient { +namespace Quotient { class Connection; class Room; class RoomMemberEvent; @@ -160,5 +160,5 @@ private: class Private; QScopedPointer d; }; -} // namespace QMatrixClient -Q_DECLARE_METATYPE(QMatrixClient::User*) +} // namespace Quotient +Q_DECLARE_METATYPE(Quotient::User*) -- cgit v1.2.3 From 8b9207d5a04386957d8eab8dd251421eaaa7c0d2 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 20 Oct 2019 19:13:56 +0900 Subject: Qualify types in signals and Q_INVOKABLEs Because https://doc.qt.io/qt-5/moc.html#limitations . For direct connections that doesn't matter but it very much does for queued ones. Along with this DirectChatsMap and IgnoredUsersList have been moved from Connection:: to Quotient::. --- lib/user.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index c9e3dbc1..28ec841b 100644 --- a/lib/user.h +++ b/lib/user.h @@ -107,9 +107,10 @@ public: qreal hueF() const; const Avatar& avatarObject(const Room* room = nullptr) const; - Q_INVOKABLE QImage avatar(int dimension, const Room* room = nullptr); + Q_INVOKABLE QImage avatar(int dimension, + const Quotient::Room* room = nullptr); Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight, - const Room* room = nullptr); + const Quotient::Room* room = nullptr); QImage avatar(int width, int height, const Room* room, const Avatar::get_callback_t& callback); @@ -145,9 +146,10 @@ public slots: signals: void nameAboutToChange(QString newName, QString oldName, - const Room* roomContext); - void nameChanged(QString newName, QString oldName, const Room* roomContext); - void avatarChanged(User* user, const Room* roomContext); + 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); @@ -161,4 +163,3 @@ private: QScopedPointer d; }; } // namespace Quotient -Q_DECLARE_METATYPE(Quotient::User*) -- cgit v1.2.3 From 776c2fd5b3caa60903a3a15db728a00753e02d67 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 29 Jul 2020 08:27:11 +0200 Subject: User: deprecate bridged() and rawName() Bridge postfixes stopped being a thing long ago; since then, bridged() has nothing but an empty string, and rawName() coincides with name(). --- lib/user.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index 28ec841b..fdad08bb 100644 --- a/lib/user.h +++ b/lib/user.h @@ -65,6 +65,7 @@ public: * (such as '(IRC)') to the user name. No disambiguation is done. * \sa name, displayName */ + [[deprecated("Bridge postfixes exist no more, use name() instead")]] QString rawName(const Room* room = nullptr) const; /** Get the displayed user name @@ -88,6 +89,8 @@ public: /** * Returns the name of bridge the user is connected from or empty. */ + [[deprecated("Bridged status is no more supported; this always returns" + " an empty string")]] QString bridged() const; /** Whether the user is a guest @@ -119,7 +122,7 @@ public: /// This method is for internal use and should not be called /// from client code - // FIXME: Move it away to private in lib 0.6 + // FIXME: Move it away to private void processEvent(const RoomMemberEvent& event, const Room* r, bool firstMention); -- cgit v1.2.3 From 5010a78505a1a89b60cd5d3102e78717567354dd Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 30 Jul 2020 21:32:25 +0200 Subject: User: minor cleanup; doc-comments --- lib/user.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index fdad08bb..e4328f1d 100644 --- a/lib/user.h +++ b/lib/user.h @@ -21,7 +21,6 @@ #include "avatar.h" #include -#include namespace Quotient { class Connection; @@ -109,6 +108,10 @@ public: int hue() const; qreal hueF() const; + /// Get a reference to a user avatar object for a given room + /*! This reference should be considered short-lived: processing the next + * room member event for this user may (or may not) invalidate it. + */ const Avatar& avatarObject(const Room* room = nullptr) const; Q_INVOKABLE QImage avatar(int dimension, const Quotient::Room* room = nullptr); @@ -135,16 +138,16 @@ public slots: bool setAvatar(const QString& fileName); /** 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 + /// Create or find a direct chat with this user + /*! The resulting chat is returned asynchronously via * Connection::directChatAvailable() */ void requestDirectChat(); - /** Add the user to the ignore list */ + /// Add the user to the ignore list void ignore(); - /** Remove the user from the ignore list */ + /// Remove the user from the ignore list void unmarkIgnore(); - /** Check whether the user is in ignore list */ + /// Check whether the user is in ignore list bool isIgnored() const; signals: -- cgit v1.2.3 From dd6cf808d69eaa52f7642def5f6f94500ee9bc79 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 4 Aug 2020 17:12:56 +0200 Subject: 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. --- lib/user.h | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index e4328f1d..a3b22480 100644 --- a/lib/user.h +++ b/lib/user.h @@ -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 d; + + template + bool doSetAvatar(SourceT&& source); }; } // namespace Quotient -- cgit v1.2.3 From 7b2eb5b3a14dd198564658c143567b3eb7a879f6 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Fri, 27 Nov 2020 00:58:48 +0100 Subject: Make it compile with QT_NO_KEYWORDS --- lib/user.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index a3b22480..19f57c30 100644 --- a/lib/user.h +++ b/lib/user.h @@ -122,7 +122,7 @@ public: QString avatarMediaId(const Room* room = nullptr) const; QUrl avatarUrl(const Room* room = nullptr) const; -public slots: +public Q_SLOTS: /// Set a new name in the global user profile void rename(const QString& newName); /// Set a new name for the user in one room @@ -143,7 +143,7 @@ public slots: /// Check whether the user is in ignore list bool isIgnored() const; -signals: +Q_SIGNALS: void defaultNameChanged(); void defaultAvatarChanged(); -- cgit v1.2.3 From cd9c9296bb1ac7af7ebbbf66931e731dbf581bc8 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Sat, 26 Dec 2020 14:54:31 +0100 Subject: Port existing copyright statement to reuse using licensedigger --- lib/user.h | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index 19f57c30..d5c892ed 100644 --- a/lib/user.h +++ b/lib/user.h @@ -1,19 +1,7 @@ /****************************************************************************** - * Copyright (C) 2015 Felix Rohrbach + * SPDX-FileCopyrightText: 2015 Felix Rohrbach * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -- cgit v1.2.3 From 0a775d9b3209be15dea8b8915fc0a1c8e0046ba6 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 16 Jan 2021 18:19:45 +0100 Subject: Updated copyright statements upon Git audit After going through all the files and the history of commits on them it was clear that some copyright statements are obsolete (the code has been overwritten since) and some are missing. This commit tries best to remedy that, along with adding SPDX tags where they were still not used. Also, a minimal SPDX convention is documented for further contributions. Closes #426. --- lib/user.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index d5c892ed..f831865e 100644 --- a/lib/user.h +++ b/lib/user.h @@ -1,8 +1,6 @@ -/****************************************************************************** - * SPDX-FileCopyrightText: 2015 Felix Rohrbach - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ +// SPDX-FileCopyrightText: 2015 Felix Rohrbach +// SPDX-FileCopyrightText: 2016 Kitsune Ral +// SPDX-License-Identifier: LGPL-2.1-or-later #pragma once -- cgit v1.2.3 From 1f92a5a957f7de38ef7c2bf425b8d6ac7fa1239c Mon Sep 17 00:00:00 2001 From: Arnav Rawat Date: Mon, 22 Feb 2021 13:42:42 -0600 Subject: Adds ability remove the avatar Not possible previously --- lib/user.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index f831865e..d0926189 100644 --- a/lib/user.h +++ b/lib/user.h @@ -117,6 +117,8 @@ public Q_SLOTS: bool setAvatar(const QString& fileName); /// Upload contents of the QIODevice and set that as an avatar bool setAvatar(QIODevice* source); + /// Removes the avatar from the profile + void removeAvatar(); /// Create or find a direct chat with this user /*! The resulting chat is returned asynchronously via * Connection::directChatAvailable() -- cgit v1.2.3 From ae85fd8602cefd1b71db8cb173ed77a873dbe223 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 26 Apr 2021 17:52:49 +0200 Subject: Make it possible to load the user metadata In the normal case there is always a room that is associated with an user. So it is in most of the cases, possible to load the metadata (display name and avatar url) with the help of the room. In some cases, it is not possible. For example, when opening an user matrix link pointing to an user and not to a room. In this case, we need to load the metadata independly of the room, since the user is not linked to a room. --- lib/user.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index d0926189..e4560843 100644 --- a/lib/user.h +++ b/lib/user.h @@ -130,6 +130,10 @@ public Q_SLOTS: void unmarkIgnore(); /// Check whether the user is in ignore list bool isIgnored() const; + /// Force loading displayName and avartar url. This is required in + /// some cases where the you need to use an user independent of the + /// room. + void load(); Q_SIGNALS: void defaultNameChanged(); -- cgit v1.2.3 From bf6303c41264d913ca049009034aa948464b8f30 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sat, 7 Aug 2021 22:14:06 +0200 Subject: User::avatar: add const --- lib/user.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index e4560843..4ff62951 100644 --- a/lib/user.h +++ b/lib/user.h @@ -99,11 +99,11 @@ public: */ const Avatar& avatarObject(const Room* room = nullptr) const; Q_INVOKABLE QImage avatar(int dimension, - const Quotient::Room* room = nullptr); + const Quotient::Room* room = nullptr) const; Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight, - const Quotient::Room* room = nullptr); + const Quotient::Room* room = nullptr) const; QImage avatar(int width, int height, const Room* room, - const Avatar::get_callback_t& callback); + const Avatar::get_callback_t& callback) const; QString avatarMediaId(const Room* room = nullptr) const; QUrl avatarUrl(const Room* room = nullptr) const; -- cgit v1.2.3 From c26015503aa0fbca37abdfc4870ac94bb7befeee Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 22 Aug 2021 20:19:15 +0200 Subject: Drop other stuff deprecated pre- or early 0.6 BaseJob: StatusCode::JsonParseError Connection: resolved() and reconnected() signals; roomMap(); postReceipt() User: bridged() and rawName() ConnectionData: setHost() and setPort() StateEventBase: prev_content() --- lib/user.h | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index 4ff62951..78b72bf2 100644 --- a/lib/user.h +++ b/lib/user.h @@ -22,7 +22,6 @@ class User : public QObject { 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: @@ -40,18 +39,10 @@ public: * This may be empty if the user didn't choose the name or cleared * it. If the user is bridged, the bridge postfix (such as '(IRC)') * is stripped out. No disambiguation for the room is done. - * \sa displayName, rawName + * \sa displayName */ QString name(const Room* room = nullptr) const; - /** Get the user name along with the bridge postfix - * This function is similar to name() but appends the bridge postfix - * (such as '(IRC)') to the user name. No disambiguation is done. - * \sa name, displayName - */ - [[deprecated("Bridge postfixes exist no more, use name() instead")]] - QString rawName(const Room* room = nullptr) const; - /** Get the displayed user name * When \p room is null, this method returns result of name() if * the name is non-empty; otherwise it returns user id. @@ -70,13 +61,6 @@ public: */ QString fullName(const Room* room = nullptr) const; - /** - * Returns the name of bridge the user is connected from or empty. - */ - [[deprecated("Bridged status is no more supported; this always returns" - " an empty string")]] - QString bridged() const; - /** Whether the user is a guest * As of now, the function relies on the convention used in Synapse * that guests and only guests have all-numeric IDs. This may or -- cgit v1.2.3 From 7350fe82953cf6274b8845a890eafb21a09b9931 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Wed, 29 Dec 2021 15:59:58 +0100 Subject: Add QUOTIENT_API throughout non-generated code This include all (hopefully) classes/structures and functions that have non-inline definitions, as well as namespaces with Q_NAMESPACE since those have non-inline (as of Qt 5.15) QMetaObject - for that a new macro, QUO_NAMESPACE, has been devised to accommodate the lack of Q_NAMESPACE_EXPORT in Qt before 5.14. --- lib/user.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index 78b72bf2..435304ce 100644 --- a/lib/user.h +++ b/lib/user.h @@ -5,6 +5,7 @@ #pragma once #include "avatar.h" +#include "quotient_export.h" #include @@ -13,7 +14,7 @@ class Connection; class Room; class RoomMemberEvent; -class User : public QObject { +class QUOTIENT_API User : public QObject { Q_OBJECT Q_PROPERTY(QString id READ id CONSTANT) Q_PROPERTY(bool isGuest READ isGuest CONSTANT) -- cgit v1.2.3 From 7d37d296f942ac993d041b4576ed52265170c4a8 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 2 Jan 2022 06:03:26 +0100 Subject: Add ImplPtr and makeImpl The original (more complex and comprehensive) solution belongs to https://oliora.github.io/2015/12/29/pimpl-and-rule-of-zero.html - this commit only provides a small wrapper for non-copyable Private class implementations common throughout libQuotient. Unlike the original, default initialisation is made explicit - you have to pass ZeroImpl() instead (and I firmly believe it's a good thing: normally pointers to Private should not remain nullptr). The reason ZeroImpl<> is not a template variable is quite simple: unique_ptr is non-copyable and so cannot be initialised from; while a template function will initialise the value in-place thanks to copy elision. --- lib/user.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index 435304ce..8412b7fd 100644 --- a/lib/user.h +++ b/lib/user.h @@ -5,7 +5,7 @@ #pragma once #include "avatar.h" -#include "quotient_export.h" +#include "util.h" #include @@ -27,7 +27,6 @@ class QUOTIENT_API User : public QObject { Q_PROPERTY(QUrl avatarUrl READ avatarUrl NOTIFY defaultAvatarChanged) public: User(QString userId, Connection* connection); - ~User() override; Connection* connection() const; @@ -126,7 +125,7 @@ Q_SIGNALS: private: class Private; - QScopedPointer d; + ImplPtr d; template bool doSetAvatar(SourceT&& source); -- cgit v1.2.3 From 9ae0d4e45befc79f621b03dc4efe869cd4277e06 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 23 Jan 2022 10:32:40 +0100 Subject: Refactor Room::setState() There are two important aspects here: - Introducing Room::setState(evtType, stateKey, contentJson). These components are ultimately what is getting sent to the homeserver, so it makes sense to expose a respective `setState()` overload. Unlike setState(event) the new overload can be Q_INVOKABLE. - Room::setState() is no more const. Although it doesn't cause any changes in Room class (and only transient changes in Room::Private), it ultimately initiates a change in the room state, so calling it const has always been a bit of hypocrisy. If you relied on that, you most likely do something wrong (see the fix to User::rename() in this very commit for a simple example of such wrongness). Also: the backend is simplified by calling the original templated Room::setState() instead of calling Room::Private::requestSetState() that does exactly the same thing. --- lib/user.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/user.h') diff --git a/lib/user.h b/lib/user.h index 8412b7fd..dfbff4a0 100644 --- a/lib/user.h +++ b/lib/user.h @@ -96,7 +96,7 @@ public Q_SLOTS: /// Set a new name in the global user profile void rename(const QString& newName); /// Set a new name for the user in one room - void rename(const QString& newName, const Room* r); + void rename(const QString& newName, Room* r); /// 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 -- cgit v1.2.3