aboutsummaryrefslogtreecommitdiff
path: root/lib/connection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r--lib/connection.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 4c0fe6b8..998282d3 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -83,6 +83,8 @@ class Connection::Private
// separately so we should, e.g., keep objects for Invite and
// Leave state of the same room.
QHash<QPair<QString, bool>, Room*> roomMap;
+ // Mapping from aliases to room ids, as per the last sync
+ QHash<QString, QString> roomAliasMap;
QVector<QString> roomIdsToForget;
QVector<Room*> firstTimeRooms;
QVector<QString> pendingStateRoomIds;
@@ -802,6 +804,41 @@ Room* Connection::room(const QString& roomId, JoinStates states) const
return nullptr;
}
+Room* Connection::roomByAlias(const QString& roomAlias, JoinStates states) const
+{
+ const auto id = d->roomAliasMap.value(roomAlias);
+ if (!id.isEmpty())
+ return room(id, states);
+ qCWarning(MAIN) << "Room for alias" << roomAlias
+ << "is not found under account" << userId();
+ return nullptr;
+}
+
+void Connection::updateRoomAliases(const QString& roomId,
+ const QStringList& previousRoomAliases,
+ const QStringList& roomAliases)
+{
+ for (const auto& a: previousRoomAliases)
+ if (d->roomAliasMap.remove(a) == 0)
+ qCWarning(MAIN) << "Alias" << a << "is not found (already deleted?)";
+
+ for (const auto& a: roomAliases)
+ {
+ auto& mappedId = d->roomAliasMap[a];
+ if (!mappedId.isEmpty())
+ {
+ if (mappedId == roomId)
+ qCDebug(MAIN) << "Alias" << a << "is already mapped to room"
+ << roomId;
+ else
+ qCWarning(MAIN) << "Alias" << a
+ << "will be force-remapped from room"
+ << mappedId << "to" << roomId;
+ }
+ mappedId = roomId;
+ }
+}
+
Room* Connection::invitation(const QString& roomId) const
{
return d->roomMap.value({roomId, true}, nullptr);