diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-03-22 21:05:21 +0100 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-03-25 22:35:23 +0100 |
commit | 9e58bbe349205ded067fdc92c221fa128a05820f (patch) | |
tree | 1a486cf1ca9b465f860413204f9b0590c7da5192 /lib | |
parent | 80c1747137a3f799a20c4d1f3d1a2baa72084adb (diff) | |
download | libquotient-9e58bbe349205ded067fdc92c221fa128a05820f.tar.gz libquotient-9e58bbe349205ded067fdc92c221fa128a05820f.zip |
Fix missing alias updates; make Room aliases accessors work (using MSC2432)
Backport of #383 to 0.5.x branch. Fixes #301.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/room.cpp | 54 | ||||
-rw-r--r-- | lib/room.h | 1 |
2 files changed, 44 insertions, 11 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index 9e7ff8d2..0942d730 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -377,7 +377,17 @@ QString Room::name() const QStringList Room::aliases() const { - return d->getCurrentState<RoomAliasesEvent>()->aliases(); + const auto* evt = d->getCurrentState<RoomCanonicalAliasEvent>(); + auto aliases = fromJson<QStringList>(evt->contentJson()["alt_aliases"]); + if (!evt->alias().isEmpty()) + aliases << evt->alias(); + return aliases; +} + +QStringList Room::altAliases() const +{ + const auto* evt = d->getCurrentState<RoomCanonicalAliasEvent>(); + return fromJson<QStringList>(evt->contentJson()["alt_aliases"]); } QString Room::canonicalAlias() const @@ -1331,7 +1341,7 @@ void Room::updateData(SyncRoomData&& data, bool fromCache) if (roomChanges&TopicChange) emit topicChanged(); - if (roomChanges&NameChange) + if (roomChanges&(NameChange|CanonicalAliasChange)) emit namesChanged(this); if (roomChanges&MembersChange) @@ -1608,12 +1618,18 @@ void Room::setName(const QString& newName) void Room::setCanonicalAlias(const QString& newAlias) { - d->requestSetState(RoomCanonicalAliasEvent(newAlias)); + connection()->callApi<SetRoomStateJob>( + id(), RoomCanonicalAliasEvent::matrixTypeId(), + QJsonObject { { "alias", newAlias }, + { "alt_aliases", QMatrixClient::toJson(altAliases()) } }); } void Room::setAliases(const QStringList& aliases) { - d->requestSetState(RoomAliasesEvent(aliases)); + connection()->callApi<SetRoomStateJob>( + id(), RoomCanonicalAliasEvent::matrixTypeId(), + QJsonObject { { "alias", canonicalAlias() }, + { "alt_aliases", QMatrixClient::toJson(aliases) } }); } void Room::setTopic(const QString& newTopic) @@ -2183,15 +2199,31 @@ Room::Changes Room::processStateEvent(const RoomEvent& e) , [] (const RoomNameEvent&) { return NameChange; } - , [this,oldStateEvent] (const RoomAliasesEvent& ae) { - const auto previousAliases = oldStateEvent - ? static_cast<const RoomAliasesEvent*>(oldStateEvent)->aliases() - : QStringList(); - connection()->updateRoomAliases(id(), previousAliases, ae.aliases()); - return OtherChange; + , [] (const RoomAliasesEvent&) { + // This event has been removed by MSC-2432 + return NoChange; } - , [this] (const RoomCanonicalAliasEvent& evt) { + , [this, oldStateEvent] (const RoomCanonicalAliasEvent& evt) { setObjectName(evt.alias().isEmpty() ? d->id : evt.alias()); + + auto prevAliases = oldStateEvent ? fromJson<QStringList>( + oldStateEvent->contentJson()["alt_aliases"]) + : QStringList(); + if (oldStateEvent) { + const auto prevCanonicalAlias = + static_cast<const RoomCanonicalAliasEvent*>(oldStateEvent) + ->alias(); + if (!prevCanonicalAlias.isEmpty()) + prevAliases.push_back(prevCanonicalAlias); + } + + auto newAliases = + fromJson<QStringList>(evt.contentJson()["alt_aliases"]); + if (!evt.alias().isEmpty()) + newAliases.push_back(evt.alias()); + + connection()->updateRoomAliases(id(), prevAliases, newAliases); + return CanonicalAliasChange; } , [] (const RoomTopicEvent&) { @@ -154,6 +154,7 @@ namespace QMatrixClient QString successorId() const; QString name() const; QStringList aliases() const; + QStringList altAliases() const; QString canonicalAlias() const; QString displayName() const; QString topic() const; |