aboutsummaryrefslogtreecommitdiff
path: root/user.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-10-14 01:13:13 +0200
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-10-14 09:17:40 +0200
commit2bf912d6e6ddd9ff81a92ff28ac8c4c1d8f2d7e1 (patch)
treef2a1299e13f48a23e0c29467f286ee3209182b00 /user.cpp
parent608e7a7163583e2e30cd6c3e9de7449c41651ca4 (diff)
downloadlibquotient-2bf912d6e6ddd9ff81a92ff28ac8c4c1d8f2d7e1.tar.gz
libquotient-2bf912d6e6ddd9ff81a92ff28ac8c4c1d8f2d7e1.zip
Support of changing the display name
Note that although the mechanism is generic enough to change any user's display name, The Spec states that power rules are very strict about it.
Diffstat (limited to 'user.cpp')
-rw-r--r--user.cpp36
1 files changed, 25 insertions, 11 deletions
diff --git a/user.cpp b/user.cpp
index 12eb2e0b..7caf54e2 100644
--- a/user.cpp
+++ b/user.cpp
@@ -22,7 +22,7 @@
#include "events/event.h"
#include "events/roommemberevent.h"
#include "jobs/mediathumbnailjob.h"
-#include "util.h"
+#include "jobs/generated/profile.h"
#include <QtCore/QTimer>
#include <QtCore/QDebug>
@@ -80,6 +80,22 @@ QString User::name() const
return d->name;
}
+void User::setName(const QString& newName)
+{
+ const auto oldName = name();
+ if (d->name != oldName)
+ {
+ d->name = newName;
+ emit nameChanged(this, oldName);
+ }
+}
+
+void User::rename(const QString& newName)
+{
+ auto job = d->connection->callApi<SetDisplayNameJob>(id(), newName);
+ connect(job, &BaseJob::success, this, [=] { setName(newName); });
+}
+
QString User::displayname() const
{
if( !d->name.isEmpty() )
@@ -140,18 +156,15 @@ void User::processEvent(Event* event)
if (e->membership() == MembershipType::Leave)
return;
- if( d->name != e->displayName() )
+ auto newName = e->displayName();
+ QRegularExpression reSuffix(" \\((IRC|Gitter)\\)$");
+ auto match = reSuffix.match(d->name);
+ if (match.hasMatch())
{
- const auto oldName = d->name;
- d->name = e->displayName();
- QRegularExpression reSuffix(" \\((IRC|Gitter)\\)$");
- auto match = reSuffix.match(d->name);
- if (match.hasMatch()) {
- d->bridged = match.captured(1);
- d->name = d->name.left(match.capturedStart(0));
- }
- emit nameChanged(this, oldName);
+ d->bridged = match.captured(1);
+ newName.truncate(match.capturedStart(0));
}
+ setName(newName);
if( d->avatarUrl != e->avatarUrl() )
{
d->avatarUrl = e->avatarUrl();
@@ -176,3 +189,4 @@ void User::Private::requestAvatar()
emit q->avatarChanged(q);
});
}
+