aboutsummaryrefslogtreecommitdiff
path: root/user.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-30 16:05:56 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-30 16:06:39 +0900
commit20be17094ea2d371e98638f3988dff0d65fae917 (patch)
tree5a1d0d9fed0d0e36b4744901fbe550e310aa0c25 /user.cpp
parent89a9656025e938a24a2ce8949e7aaf1aacaae37b (diff)
downloadlibquotient-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.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/user.cpp b/user.cpp
index b0890b61..6cc2e0a5 100644
--- a/user.cpp
+++ b/user.cpp
@@ -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;
}