diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-01-28 21:28:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-28 21:28:47 +0100 |
commit | b39b70bf90d816377b2873a5c2506bd256c0a00e (patch) | |
tree | d3ab6da61f0bd7d69bd66a63e450a6f4d85895f0 /lib/user.cpp | |
parent | cc9908e5159ed93a18eda9f9794a7c9fc7f67f27 (diff) | |
parent | 1747575321cda4fc11f90c2ffb2148a69d0d9946 (diff) | |
download | libquotient-b39b70bf90d816377b2873a5c2506bd256c0a00e.tar.gz libquotient-b39b70bf90d816377b2873a5c2506bd256c0a00e.zip |
Merge pull request #525 from quotient-im/kitsune/query-current-state
Move out current room state to its own class
Diffstat (limited to 'lib/user.cpp')
-rw-r--r-- | lib/user.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/user.cpp b/lib/user.cpp index 0dbc444a..4c3fc9e2 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -110,7 +110,7 @@ void User::rename(const QString& newName) }); } -void User::rename(const QString& newName, const Room* r) +void User::rename(const QString& newName, Room* r) { if (!r) { qCWarning(MAIN) << "Passing a null room to two-argument User::rename()" @@ -119,12 +119,17 @@ void User::rename(const QString& newName, const Room* r) return; } // #481: take the current state and update it with the new name - auto evtC = r->getCurrentState<RoomMemberEvent>(id())->content(); - Q_ASSERT_X(evtC.membership == Membership::Join, __FUNCTION__, - "Attempt to rename a user that's not a room member"); - evtC.displayName = sanitized(newName); - r->setState<RoomMemberEvent>(id(), move(evtC)); - // The state will be updated locally after it arrives with sync + if (const auto& maybeEvt = r->currentState().get<RoomMemberEvent>(id())) { + auto content = maybeEvt->content(); + if (content.membership == Membership::Join) { + content.displayName = sanitized(newName); + r->setState<RoomMemberEvent>(id(), move(content)); + // The state will be updated locally after it arrives with sync + return; + } + } + qCCritical(MEMBERS) + << "Attempt to rename a non-member in a room context - ignored"; } template <typename SourceT> |