From 2bf912d6e6ddd9ff81a92ff28ac8c4c1d8f2d7e1 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 14 Oct 2017 01:13:13 +0200 Subject: 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. --- user.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'user.cpp') 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 #include @@ -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(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); }); } + -- cgit v1.2.3 From c1049d374a3c6d79750c57d2e1751d440df3d8cc Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 17 Oct 2017 17:11:25 +0900 Subject: Fixed a blunder leading to users not having names If all users suddenly don't have names, update to this commit, delete your cache and run again. Issue since 2bf912d6e6ddd9ff81a92ff28ac8c4c1d8f2d7e1. --- user.cpp | 10 ++++++---- user.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'user.cpp') diff --git a/user.cpp b/user.cpp index 7caf54e2..171d6d6c 100644 --- a/user.cpp +++ b/user.cpp @@ -80,11 +80,13 @@ QString User::name() const return d->name; } -void User::setName(const QString& newName) +void User::updateName(const QString& newName) { const auto oldName = name(); - if (d->name != oldName) + if (d->name != newName) { + qCDebug(MAIN) << "Renaming" << id() + << "from" << oldName << "to" << newName; d->name = newName; emit nameChanged(this, oldName); } @@ -93,7 +95,7 @@ void User::setName(const QString& newName) void User::rename(const QString& newName) { auto job = d->connection->callApi(id(), newName); - connect(job, &BaseJob::success, this, [=] { setName(newName); }); + connect(job, &BaseJob::success, this, [=] { updateName(newName); }); } QString User::displayname() const @@ -164,7 +166,7 @@ void User::processEvent(Event* event) d->bridged = match.captured(1); newName.truncate(match.capturedStart(0)); } - setName(newName); + updateName(newName); if( d->avatarUrl != e->avatarUrl() ) { d->avatarUrl = e->avatarUrl(); diff --git a/user.h b/user.h index cf7d4e0a..79a6f5db 100644 --- a/user.h +++ b/user.h @@ -67,7 +67,7 @@ namespace QMatrixClient void avatarChanged(User* user); private slots: - void setName(const QString& newName); + void updateName(const QString& newName); private: class Private; -- cgit v1.2.3