From 00f2fe7fe66321ca8773e377db4f0fa12bf5c64d Mon Sep 17 00:00:00 2001 From: Karthik Nishanth Date: Thu, 4 Jul 2024 10:38:32 -0700 Subject: [PATCH] wip change how we read parent room todo remove it from the cache --- src/RoomsModel.cpp | 22 +++++++++++++++++++--- src/RoomsModel.h | 5 ++++- src/timeline/TimelineViewManager.cpp | 4 ++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/RoomsModel.cpp b/src/RoomsModel.cpp index 034a3ce25..d07277f20 100644 --- a/src/RoomsModel.cpp +++ b/src/RoomsModel.cpp @@ -8,11 +8,14 @@ #include "Cache_p.h" #include "CompletionModelRoles.h" +#include "RoomlistModel.h" +#include "TimelineModel.h" #include "UserSettingsPage.h" #include "Utils.h" -RoomsModel::RoomsModel(bool showOnlyRoomWithAliases, QObject *parent) +RoomsModel::RoomsModel(RoomlistModel &roomlistModel, bool showOnlyRoomWithAliases, QObject *parent) : QAbstractListModel(parent) + , roomListModel_(roomlistModel) , showOnlyRoomWithAliases_(showOnlyRoomWithAliases) { rooms = cache::client()->roomNamesAndAliases(); @@ -73,8 +76,21 @@ 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); + case Roles::RoomParent: { + const auto roomPtr = roomListModel_.getRoomById(QString::fromStdString(rooms[index.row()].id)); + if (auto &room = *roomPtr; roomPtr) { + if (const auto &parent = room.parentSpace(); parent) { + qInfo() << "Parent has name" << parent->roomName(); + return parent->roomName(); + } else { + qWarning() << "No parent for room" << "expected" << rooms[index.row()].parent; + } + } + else { + qWarning() << "No room with ID"; + } + return QString{}; + } } } return {}; diff --git a/src/RoomsModel.h b/src/RoomsModel.h index 5d3d3813c..845f22ba7 100644 --- a/src/RoomsModel.h +++ b/src/RoomsModel.h @@ -9,6 +9,8 @@ #include #include +class RoomlistModel; + class RoomsModel final : public QAbstractListModel { public: @@ -23,7 +25,7 @@ class RoomsModel final : public QAbstractListModel RoomParent, }; - RoomsModel(bool showOnlyRoomWithAliases = false, QObject *parent = nullptr); + RoomsModel(RoomlistModel &roomListModel, bool showOnlyRoomWithAliases = false, QObject *parent = nullptr); QHash roleNames() const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override { @@ -33,6 +35,7 @@ class RoomsModel final : public QAbstractListModel QVariant data(const QModelIndex &index, int role) const override; private: + RoomlistModel &roomListModel_; std::vector rooms; bool showOnlyRoomWithAliases_; }; diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 09af254c8..fd7a340f7 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -517,12 +517,12 @@ TimelineViewManager::completerFor(const QString &completerName, const QString &r emojiModel->setParent(proxy); return proxy; } else if (completerName == QLatin1String("room")) { - auto roomModel = new RoomsModel(false); + auto roomModel = new RoomsModel(*rooms_, false); auto proxy = new CompletionProxyModel(roomModel, 4); roomModel->setParent(proxy); return proxy; } else if (completerName == QLatin1String("roomAliases")) { - auto roomModel = new RoomsModel(true); + auto roomModel = new RoomsModel(*rooms_, true); auto proxy = new CompletionProxyModel(roomModel); roomModel->setParent(proxy); return proxy;