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 /user.cpp | |
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.
Diffstat (limited to 'user.cpp')
-rw-r--r-- | user.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
@@ -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; } |