aboutsummaryrefslogtreecommitdiff
path: root/user.cpp
diff options
context:
space:
mode:
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);
});
}
+