aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--user.cpp36
-rw-r--r--user.h4
2 files changed, 29 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);
});
}
+
diff --git a/user.h b/user.h
index a2d58908..cf7d4e0a 100644
--- a/user.h
+++ b/user.h
@@ -60,11 +60,15 @@ namespace QMatrixClient
public slots:
void requestAvatar();
+ void rename(const QString& newName);
signals:
void nameChanged(User*, QString);
void avatarChanged(User* user);
+ private slots:
+ void setName(const QString& newName);
+
private:
class Private;
Private* d;