diff --git a/resources/qml/Completer.qml b/resources/qml/Completer.qml index c6fea98e..2d635434 100644 --- a/resources/qml/Completer.qml +++ b/resources/qml/Completer.qml @@ -249,6 +249,11 @@ Control { text: model.roomName textFormat: Text.RichText } + + Label { + text: model.roomParent === "" ? "" : ("[" + model.roomParent + "]") + font.pixelSize: popup.avatarHeight * 0.5 + } } } DelegateChoice { diff --git a/src/Cache.cpp b/src/Cache.cpp index e12e9512..bd8d8f76 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -26,6 +26,7 @@ #include +#include #include #include @@ -2945,6 +2946,26 @@ Cache::roomNamesAndAliases() { auto txn = ro_txn(env_); + auto getParentRoomIdsWithTxn = [&](const std::string &id) -> std::optional { + auto cursor = lmdb::cursor::open(txn, spacesParentsDb_); + std::string_view sp = id, space_parent; + if (cursor.get(sp, space_parent, MDB_SET)) { + while (cursor.get(sp, space_parent, MDB_FIRST_DUP)) { + if (!space_parent.empty()) + return std::make_optional(static_cast(space_parent)); + } + } + cursor.close(); + + return std::nullopt; + }; + + auto getRoomName = [&](const std::string &roomId) { + auto spaceDb = getStatesDb(txn, roomId); + auto membersDb = getMembersDb(txn, roomId); + return Cache::getRoomName(txn, spaceDb, membersDb).toStdString(); + }; + std::vector result; result.reserve(roomsDb_.size(txn)); @@ -2962,6 +2983,15 @@ Cache::roomNamesAndAliases() alias = aliases->content.alias; } + auto parentId = getParentRoomIdsWithTxn(room_id_str); + auto parentName = std::string{}; + + if (parentId) { + parentName = getRoomName(*parentId); + } + + nhlog::db()->info("{} has parent [{}]", room_id_str, parentName); + result.push_back(RoomNameAlias{ .id = std::move(room_id_str), .name = std::move(info.name), @@ -2969,6 +2999,7 @@ Cache::roomNamesAndAliases() .recent_activity = info.approximate_last_modification_ts, .is_tombstoned = info.is_tombstoned, .is_space = info.is_space, + .parent = std::move(parentName), }); } catch (std::exception &e) { nhlog::db()->warn("Failed to add room {} to result: {}", room_id, e.what()); diff --git a/src/CacheStructs.h b/src/CacheStructs.h index f1aafb96..18dadc10 100644 --- a/src/CacheStructs.h +++ b/src/CacheStructs.h @@ -111,6 +111,7 @@ struct RoomNameAlias std::uint64_t recent_activity; bool is_tombstoned; bool is_space; + std::string parent; }; //! Basic information per member. diff --git a/src/RoomsModel.cpp b/src/RoomsModel.cpp index fff9cbc6..034a3ce2 100644 --- a/src/RoomsModel.cpp +++ b/src/RoomsModel.cpp @@ -35,6 +35,7 @@ RoomsModel::roleNames() const {Roles::AvatarUrl, "avatarUrl"}, {Roles::RoomID, "roomid"}, {Roles::RoomName, "roomName"}, + {Roles::RoomParent, "roomParent"}, {Roles::IsTombstoned, "isTombstoned"}, {Roles::IsSpace, "isSpace"}, }; @@ -72,6 +73,8 @@ RoomsModel::data(const QModelIndex &index, int role) const return rooms[index.row()].is_tombstoned; case Roles::IsSpace: return rooms[index.row()].is_space; + case Roles::RoomParent: + return QString::fromStdString(rooms[index.row()].parent); } } return {}; diff --git a/src/RoomsModel.h b/src/RoomsModel.h index 83a21ae0..5d3d3813 100644 --- a/src/RoomsModel.h +++ b/src/RoomsModel.h @@ -20,6 +20,7 @@ public: RoomName, IsTombstoned, IsSpace, + RoomParent, }; RoomsModel(bool showOnlyRoomWithAliases = false, QObject *parent = nullptr);