diff options
-rw-r--r-- | user.cpp | 36 | ||||
-rw-r--r-- | user.h | 4 |
2 files changed, 29 insertions, 11 deletions
@@ -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); }); } + @@ -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; |