From 780d1b61c37a89f93eb58fb271083444f775acd2 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 27 Jun 2021 07:11:06 +0200 Subject: Retain the current room member avatar when renaming Closes #481. Note: the library doesn't even have the API in User to set per-room avatars; one still can achieve that by calling Room::setState(...) though (and it's likely to be _the_ recommended way to deal with per-room user profiles in 0.7, with User being entirely deprecated). --- lib/user.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/user.cpp') diff --git a/lib/user.cpp b/lib/user.cpp index 85f9d9a7..7143620f 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -176,6 +176,8 @@ void User::rename(const QString& newName, const Room* r) const auto actualNewName = sanitized(newName); MemberEventContent evtC; evtC.displayName = actualNewName; + // #481: fill in the current avatar URL in order to not clear it out + evtC.avatarUrl = r->getCurrentState(id())->avatarUrl(); r->setState(id(), move(evtC)); // The state will be updated locally after it arrives with sync } -- cgit v1.2.3 From 3d2af27dbba9bf9de238002cb64d6f8046a25a2b Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Wed, 14 Jul 2021 19:55:46 +0200 Subject: User::rename(): actually build on the current state This is a further extension of #481 fix that takes the whole current state event content, rather than just the avatar URL. --- lib/user.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'lib/user.cpp') diff --git a/lib/user.cpp b/lib/user.cpp index 7143620f..f0831733 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -171,13 +171,11 @@ void User::rename(const QString& newName, const Room* r) rename(newName); return; } - Q_ASSERT_X(r->memberJoinState(this) == JoinState::Join, __FUNCTION__, + // #481: take the current state and update it with the new name + auto evtC = r->getCurrentState(id())->content(); + Q_ASSERT_X(evtC.membership == MembershipType::Join, __FUNCTION__, "Attempt to rename a user that's not a room member"); - const auto actualNewName = sanitized(newName); - MemberEventContent evtC; - evtC.displayName = actualNewName; - // #481: fill in the current avatar URL in order to not clear it out - evtC.avatarUrl = r->getCurrentState(id())->avatarUrl(); + evtC.displayName = sanitized(newName); r->setState(id(), move(evtC)); // The state will be updated locally after it arrives with sync } -- cgit v1.2.3 From 8398e7118503d51da431ba850812ec76d1976b67 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sat, 31 Jul 2021 22:07:29 +0200 Subject: Fix lack of percent encoding in User::fetchProfile Users with slashes in their ids do it at their own peril of course but to encode the id in the URL is a good thing in any case. Too bad it's pretty invisible and has to be dealt with case by case, instead of GTAD magically sticking QUrl::toPercentEncoding() where appropriate in the generated code. --- lib/user.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/user.cpp') diff --git a/lib/user.cpp b/lib/user.cpp index f0831733..4e369a4f 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -71,7 +71,9 @@ void User::Private::fetchProfile(const User* q) { defaultAvatar.emplace(Avatar {}); defaultName = ""; - auto* j = q->connection()->callApi(BackgroundRequest, id); + auto* j = + q->connection()->callApi(BackgroundRequest, + QUrl::toPercentEncoding(id)); // FIXME: accepting const User* and const_cast'ing it here is only // until we get a better User API in 0.7 QObject::connect(j, &BaseJob::success, q, -- cgit v1.2.3