aboutsummaryrefslogtreecommitdiff
path: root/lib/user.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-06-24 07:21:13 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-06-24 07:21:13 +0900
commit63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408 (patch)
tree2552f5049a6ef7ba0034483b25ca4ab33d1fcb13 /lib/user.h
parente083d327e6f6581210f8d077d8bbe1151e81e82c (diff)
parent93f0c8fe89f448d1d58caa757573f17102369471 (diff)
downloadlibquotient-63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408.tar.gz
libquotient-63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408.zip
Merge branch 'master' into clang-format
# Conflicts: # CMakeLists.txt # lib/avatar.cpp # lib/connection.cpp # lib/connection.h # lib/connectiondata.cpp # lib/csapi/account-data.cpp # lib/csapi/account-data.h # lib/csapi/capabilities.cpp # lib/csapi/capabilities.h # lib/csapi/content-repo.cpp # lib/csapi/create_room.cpp # lib/csapi/filter.cpp # lib/csapi/joining.cpp # lib/csapi/keys.cpp # lib/csapi/list_joined_rooms.cpp # lib/csapi/notifications.cpp # lib/csapi/openid.cpp # lib/csapi/presence.cpp # lib/csapi/pushrules.cpp # lib/csapi/registration.cpp # lib/csapi/room_upgrades.cpp # lib/csapi/room_upgrades.h # lib/csapi/search.cpp # lib/csapi/users.cpp # lib/csapi/versions.cpp # lib/csapi/whoami.cpp # lib/csapi/{{base}}.cpp.mustache # lib/events/accountdataevents.h # lib/events/eventcontent.h # lib/events/roommemberevent.cpp # lib/events/stateevent.cpp # lib/jobs/basejob.cpp # lib/jobs/basejob.h # lib/networkaccessmanager.cpp # lib/networksettings.cpp # lib/room.cpp # lib/room.h # lib/settings.cpp # lib/settings.h # lib/syncdata.cpp # lib/user.cpp # lib/user.h # lib/util.cpp
Diffstat (limited to 'lib/user.h')
-rw-r--r--lib/user.h269
1 files changed, 141 insertions, 128 deletions
diff --git a/lib/user.h b/lib/user.h
index c174314e..f4d7cff3 100644
--- a/lib/user.h
+++ b/lib/user.h
@@ -19,135 +19,148 @@
#pragma once
#include "avatar.h"
+
#include <QtCore/QObject>
#include <QtCore/QString>
-namespace QMatrixClient {
- class Connection;
- class Room;
- class RoomMemberEvent;
-
- 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)
- 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);
-
- 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;
-
- 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);
-
- 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);
-
- private:
- class Private;
- QScopedPointer<Private> d;
- };
-}
+namespace QMatrixClient
+{
+class Connection;
+class Room;
+class RoomMemberEvent;
+
+class User : public QObject
+{
+ 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)
+ 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;
+
+ /** 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,
+ 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;
+
+ /// 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 */
+ 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);
+
+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);
+
+private:
+ class Private;
+ QScopedPointer<Private> d;
+};
+} // namespace QMatrixClient
Q_DECLARE_METATYPE(QMatrixClient::User*)