Skip to content

Commit

Permalink
wip change how we read parent room
Browse files Browse the repository at this point in the history
todo remove it from the cache
  • Loading branch information
nishanthkarthik committed Jul 4, 2024
1 parent 492511a commit 00f2fe7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
22 changes: 19 additions & 3 deletions src/RoomsModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 {};
Expand Down
5 changes: 4 additions & 1 deletion src/RoomsModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <QAbstractListModel>
#include <QString>

class RoomlistModel;

class RoomsModel final : public QAbstractListModel
{
public:
Expand All @@ -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<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override
{
Expand All @@ -33,6 +35,7 @@ class RoomsModel final : public QAbstractListModel
QVariant data(const QModelIndex &index, int role) const override;

private:
RoomlistModel &roomListModel_;
std::vector<RoomNameAlias> rooms;
bool showOnlyRoomWithAliases_;
};
4 changes: 2 additions & 2 deletions src/timeline/TimelineViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 00f2fe7

Please sign in to comment.