diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-01-30 16:05:56 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-01-30 16:06:39 +0900 |
commit | 20be17094ea2d371e98638f3988dff0d65fae917 (patch) | |
tree | 5a1d0d9fed0d0e36b4744901fbe550e310aa0c25 | |
parent | 89a9656025e938a24a2ce8949e7aaf1aacaae37b (diff) | |
download | libquotient-20be17094ea2d371e98638f3988dff0d65fae917.tar.gz libquotient-20be17094ea2d371e98638f3988dff0d65fae917.zip |
User: fullName, isGuest, better doc comments
User::fullName() is used in Room::roomMembername now. That string
construction may be further cached now if it ever becomes a bottleneck.
-rw-r--r-- | room.cpp | 4 | ||||
-rw-r--r-- | user.cpp | 25 | ||||
-rw-r--r-- | user.h | 35 |
3 files changed, 52 insertions, 12 deletions
@@ -790,8 +790,8 @@ QString Room::roomMembername(const User* u) const // << "is not a member of the room" << id(); // } - // In case of more than one namesake, disambiguate with user id. - return username % " (" % u->id() % ")"; + // In case of more than one namesake, use the full name to disambiguate + return u->fullName(); } QString Room::roomMembername(const QString& userId) const @@ -28,6 +28,9 @@ #include <QtCore/QTimer> #include <QtCore/QRegularExpression> #include <QtCore/QPointer> +#include <QtCore/QStringBuilder> + +#include <functional> using namespace QMatrixClient; @@ -65,6 +68,15 @@ QString User::id() const return d->userId; } +bool User::isGuest() const +{ + Q_ASSERT(!d->userId.isEmpty() && d->userId.front() == '@'); + auto it = std::find_if_not(d->userId.begin() + 1, d->userId.end(), + std::mem_fn(&QChar::isDigit)); + Q_ASSERT(it == d->userId.end()); + return *it == ':'; +} + QString User::name() const { return d->name; @@ -121,12 +133,17 @@ void User::Private::setAvatar(UploadContentJob* job, User* q) QString User::displayname() const { - if( !d->name.isEmpty() ) - return d->name; - return d->userId; + return d->name.isEmpty() ? d->userId : d->name; } -QString User::bridged() const { +QString User::fullName() const +{ + return d->name.isEmpty() ? d->userId : + d->name % '(' % d->userId % ')'; +} + +QString User::bridged() const +{ return d->bridged; } @@ -30,8 +30,10 @@ namespace QMatrixClient { 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) @@ -39,26 +41,47 @@ namespace QMatrixClient User(QString userId, Connection* connection); ~User() override; - /** - * Returns the id of the user + /** Get unique stable user id + * User id is generated by the server and is not changed ever. */ QString id() const; - /** - * Returns the name chosen by the user + /** Get the name chosen by the user + * This may be empty if the user didn't choose the name or cleared + * it. + * \sa displayName */ QString name() const; - /** - * Returns the name that should be used to display the user. + /** Get the displayed user name + * This method returns the result of name() if its non-empty; + * otherwise it returns user id. This is convenient to show a user + * name outside of a room context. In a room context, user names + * should be disambiguated. + * \sa name, id, fullName Room::roomMembername */ QString displayname() const; + /** Get user name and id in one string + * The constructed string follows the format 'name (id)' + * used for users disambiguation in a room context and in other + * places. + * \sa displayName, Room::roomMembername + */ + QString fullName() 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; Q_INVOKABLE QImage avatar(int dimension); Q_INVOKABLE QImage avatar(int requestedWidth, int requestedHeight); |