wip change how we read parent room

todo remove it from the cache
This commit is contained in:
Karthik Nishanth 2024-07-04 10:38:32 -07:00
parent 492511a2af
commit 00f2fe7fe6
3 changed files with 25 additions and 6 deletions

View file

@ -8,11 +8,14 @@
#include "Cache_p.h" #include "Cache_p.h"
#include "CompletionModelRoles.h" #include "CompletionModelRoles.h"
#include "RoomlistModel.h"
#include "TimelineModel.h"
#include "UserSettingsPage.h" #include "UserSettingsPage.h"
#include "Utils.h" #include "Utils.h"
RoomsModel::RoomsModel(bool showOnlyRoomWithAliases, QObject *parent) RoomsModel::RoomsModel(RoomlistModel &roomlistModel, bool showOnlyRoomWithAliases, QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
, roomListModel_(roomlistModel)
, showOnlyRoomWithAliases_(showOnlyRoomWithAliases) , showOnlyRoomWithAliases_(showOnlyRoomWithAliases)
{ {
rooms = cache::client()->roomNamesAndAliases(); rooms = cache::client()->roomNamesAndAliases();
@ -73,8 +76,21 @@ 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: case Roles::RoomParent: {
return QString::fromStdString(rooms[index.row()].parent); 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 {}; return {};

View file

@ -9,6 +9,8 @@
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QString> #include <QString>
class RoomlistModel;
class RoomsModel final : public QAbstractListModel class RoomsModel final : public QAbstractListModel
{ {
public: public:
@ -23,7 +25,7 @@ public:
RoomParent, RoomParent,
}; };
RoomsModel(bool showOnlyRoomWithAliases = false, QObject *parent = nullptr); RoomsModel(RoomlistModel &roomListModel, bool showOnlyRoomWithAliases = false, QObject *parent = nullptr);
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override int rowCount(const QModelIndex &parent = QModelIndex()) const override
{ {
@ -33,6 +35,7 @@ public:
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
private: private:
RoomlistModel &roomListModel_;
std::vector<RoomNameAlias> rooms; std::vector<RoomNameAlias> rooms;
bool showOnlyRoomWithAliases_; bool showOnlyRoomWithAliases_;
}; };

View file

@ -517,12 +517,12 @@ TimelineViewManager::completerFor(const QString &completerName, const QString &r
emojiModel->setParent(proxy); emojiModel->setParent(proxy);
return proxy; return proxy;
} else if (completerName == QLatin1String("room")) { } else if (completerName == QLatin1String("room")) {
auto roomModel = new RoomsModel(false); auto roomModel = new RoomsModel(*rooms_, false);
auto proxy = new CompletionProxyModel(roomModel, 4); auto proxy = new CompletionProxyModel(roomModel, 4);
roomModel->setParent(proxy); roomModel->setParent(proxy);
return proxy; return proxy;
} else if (completerName == QLatin1String("roomAliases")) { } else if (completerName == QLatin1String("roomAliases")) {
auto roomModel = new RoomsModel(true); auto roomModel = new RoomsModel(*rooms_, true);
auto proxy = new CompletionProxyModel(roomModel); auto proxy = new CompletionProxyModel(roomModel);
roomModel->setParent(proxy); roomModel->setParent(proxy);
return proxy; return proxy;