aboutsummaryrefslogtreecommitdiff
path: root/lib/room.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-03-21 15:05:32 +0100
committerGitHub <noreply@github.com>2020-03-21 15:05:32 +0100
commitd06bbd6633eea048e35421b1785e96468c3cf5c0 (patch)
treeadb5c2eec08e738cbe2463a8d136e75ba179e323 /lib/room.cpp
parentc810c10da56fad0f5c07b2096cae73e8471d9f0e (diff)
parented62c822ca200613bde60e48547ba32a0bd21c13 (diff)
downloadlibquotient-d06bbd6633eea048e35421b1785e96468c3cf5c0.tar.gz
libquotient-d06bbd6633eea048e35421b1785e96468c3cf5c0.zip
Merge pull request #383 from ram-nad/msc2432-fix
fixing msc2432
Diffstat (limited to 'lib/room.cpp')
-rw-r--r--lib/room.cpp77
1 files changed, 49 insertions, 28 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index 2945111a..6ac2673e 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -56,6 +56,7 @@
#include "jobs/downloadfilejob.h"
#include "jobs/mediathumbnailjob.h"
#include "jobs/postreadmarkersjob.h"
+#include "events/roomcanonicalaliasevent.h"
#include <QtCore/QDir>
#include <QtCore/QHash>
@@ -519,11 +520,21 @@ QString Room::name() const
return d->getCurrentState<RoomNameEvent>()->name();
}
+QStringList Room::aliases() const
+{
+ const auto* evt = d->getCurrentState<RoomCanonicalAliasEvent>();
+ return QStringList(evt->altAliases()) << evt->alias();
+}
+
+QStringList Room::altAliases() const
+{
+ return d->getCurrentState<RoomCanonicalAliasEvent>()->altAliases();
+}
+
QStringList Room::localAliases() const
{
- return d
- ->getCurrentState<RoomAliasesEvent>(
- connection()->domain())
+ return d->getCurrentState<RoomAliasesEvent>(
+ connection()->domain())
->aliases();
}
@@ -1461,7 +1472,7 @@ void Room::updateData(SyncRoomData&& data, bool fromCache)
if (roomChanges & TopicChange)
emit topicChanged();
- if (roomChanges & NameChange)
+ if (roomChanges & (NameChange | AliasesChange))
emit namesChanged(this);
if (roomChanges & MembersChange)
@@ -1740,13 +1751,12 @@ void Room::setName(const QString& newName)
void Room::setCanonicalAlias(const QString& newAlias)
{
- d->requestSetState<RoomCanonicalAliasEvent>(newAlias);
+ d->requestSetState<RoomCanonicalAliasEvent>(newAlias, altAliases());
}
void Room::setLocalAliases(const QStringList& aliases)
{
- d->requestSetState<RoomAliasesEvent>(connection()->homeserver().authority(),
- aliases);
+ d->requestSetState<RoomCanonicalAliasEvent>(canonicalAlias(), aliases);
}
void Room::setTopic(const QString& newTopic)
@@ -2401,30 +2411,41 @@ Room::Changes Room::processStateEvent(const RoomEvent& e)
}
, [this,oldStateEvent] (const RoomAliasesEvent& ae) {
// clang-format on
- if (ae.aliases().isEmpty()) {
- if (d->aliasServers.remove(ae.stateKey()))
- qCDebug(STATE).noquote()
- << ae.stateKey() << "no more has aliases for room"
- << objectName();
- } else {
- d->aliasServers.insert(ae.stateKey());
- qCDebug(STATE).nospace().noquote()
- << "New server with aliases for room " << objectName()
- << ": " << ae.stateKey();
- }
- const auto previousAliases =
+ // This event has been removed by MSC-2432
+ return NoChange;
+ // clang-format off
+ }
+ , [this, oldStateEvent] (const RoomCanonicalAliasEvent& cae) {
+ // clang-format on
+ setObjectName(cae.alias().isEmpty() ? d->id : cae.alias());
+ QString previousCanonicalAlias =
oldStateEvent
- ? static_cast<const RoomAliasesEvent*>(oldStateEvent)->aliases()
+ ? static_cast<const RoomCanonicalAliasEvent*>(oldStateEvent)
+ ->alias()
+ : QString();
+
+ auto previousAltAliases =
+ oldStateEvent
+ ? static_cast<const RoomCanonicalAliasEvent*>(oldStateEvent)
+ ->altAliases()
: QStringList();
- connection()->updateRoomAliases(id(), ae.stateKey(),
- previousAliases, ae.aliases());
- return OtherChange;
+
+ if (!previousCanonicalAlias.isEmpty()) {
+ previousAltAliases.push_back(previousCanonicalAlias);
+ }
+
+ const auto previousAliases = std::move(previousAltAliases);
+
+ auto newAliases = cae.altAliases();
+
+ if (!cae.alias().isEmpty()) {
+ newAliases.push_front(cae.alias());
+ }
+
+ connection()->updateRoomAliases(id(), previousAliases, newAliases);
+ return AliasesChange;
// clang-format off
}
- , [this] (const RoomCanonicalAliasEvent& evt) {
- setObjectName(evt.alias().isEmpty() ? d->id : evt.alias());
- return CanonicalAliasChange;
- }
, [] (const RoomTopicEvent&) {
return TopicChange;
}
@@ -2671,7 +2692,7 @@ QString Room::Private::calculateDisplayname() const
return dispName;
// 3. m.room.aliases - only local aliases, subject for further removal
- const auto aliases = q->localAliases();
+ const auto aliases = q->aliases();
if (!aliases.isEmpty())
return aliases.front();