mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
List parent room name next to room names in room switcher
This commit is contained in:
parent
2b9e056eaf
commit
46a8019913
5 changed files with 41 additions and 0 deletions
|
@ -249,6 +249,11 @@ Control {
|
||||||
text: model.roomName
|
text: model.roomName
|
||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
text: model.roomParent === "" ? "" : ("[" + model.roomParent + "]")
|
||||||
|
font.pixelSize: popup.avatarHeight * 0.5
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DelegateChoice {
|
DelegateChoice {
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#include <mtx/events/spaces.hpp>
|
||||||
#include <mtx/responses/common.hpp>
|
#include <mtx/responses/common.hpp>
|
||||||
#include <mtx/responses/messages.hpp>
|
#include <mtx/responses/messages.hpp>
|
||||||
|
|
||||||
|
@ -2945,6 +2946,26 @@ Cache::roomNamesAndAliases()
|
||||||
{
|
{
|
||||||
auto txn = ro_txn(env_);
|
auto txn = ro_txn(env_);
|
||||||
|
|
||||||
|
auto getParentRoomIdsWithTxn = [&](const std::string &id) -> std::optional<std::string> {
|
||||||
|
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<std::string>(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<RoomNameAlias> result;
|
std::vector<RoomNameAlias> result;
|
||||||
result.reserve(roomsDb_.size(txn));
|
result.reserve(roomsDb_.size(txn));
|
||||||
|
|
||||||
|
@ -2962,6 +2983,15 @@ Cache::roomNamesAndAliases()
|
||||||
alias = aliases->content.alias;
|
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{
|
result.push_back(RoomNameAlias{
|
||||||
.id = std::move(room_id_str),
|
.id = std::move(room_id_str),
|
||||||
.name = std::move(info.name),
|
.name = std::move(info.name),
|
||||||
|
@ -2969,6 +2999,7 @@ Cache::roomNamesAndAliases()
|
||||||
.recent_activity = info.approximate_last_modification_ts,
|
.recent_activity = info.approximate_last_modification_ts,
|
||||||
.is_tombstoned = info.is_tombstoned,
|
.is_tombstoned = info.is_tombstoned,
|
||||||
.is_space = info.is_space,
|
.is_space = info.is_space,
|
||||||
|
.parent = std::move(parentName),
|
||||||
});
|
});
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
nhlog::db()->warn("Failed to add room {} to result: {}", room_id, e.what());
|
nhlog::db()->warn("Failed to add room {} to result: {}", room_id, e.what());
|
||||||
|
|
|
@ -111,6 +111,7 @@ struct RoomNameAlias
|
||||||
std::uint64_t recent_activity;
|
std::uint64_t recent_activity;
|
||||||
bool is_tombstoned;
|
bool is_tombstoned;
|
||||||
bool is_space;
|
bool is_space;
|
||||||
|
std::string parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Basic information per member.
|
//! Basic information per member.
|
||||||
|
|
|
@ -35,6 +35,7 @@ RoomsModel::roleNames() const
|
||||||
{Roles::AvatarUrl, "avatarUrl"},
|
{Roles::AvatarUrl, "avatarUrl"},
|
||||||
{Roles::RoomID, "roomid"},
|
{Roles::RoomID, "roomid"},
|
||||||
{Roles::RoomName, "roomName"},
|
{Roles::RoomName, "roomName"},
|
||||||
|
{Roles::RoomParent, "roomParent"},
|
||||||
{Roles::IsTombstoned, "isTombstoned"},
|
{Roles::IsTombstoned, "isTombstoned"},
|
||||||
{Roles::IsSpace, "isSpace"},
|
{Roles::IsSpace, "isSpace"},
|
||||||
};
|
};
|
||||||
|
@ -72,6 +73,8 @@ RoomsModel::data(const QModelIndex &index, int role) const
|
||||||
return rooms[index.row()].is_tombstoned;
|
return rooms[index.row()].is_tombstoned;
|
||||||
case Roles::IsSpace:
|
case Roles::IsSpace:
|
||||||
return rooms[index.row()].is_space;
|
return rooms[index.row()].is_space;
|
||||||
|
case Roles::RoomParent:
|
||||||
|
return QString::fromStdString(rooms[index.row()].parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -20,6 +20,7 @@ public:
|
||||||
RoomName,
|
RoomName,
|
||||||
IsTombstoned,
|
IsTombstoned,
|
||||||
IsSpace,
|
IsSpace,
|
||||||
|
RoomParent,
|
||||||
};
|
};
|
||||||
|
|
||||||
RoomsModel(bool showOnlyRoomWithAliases = false, QObject *parent = nullptr);
|
RoomsModel(bool showOnlyRoomWithAliases = false, QObject *parent = nullptr);
|
||||||
|
|
Loading…
Reference in a new issue