From 0b6c82dfffd20a264dd54ee838a33a7e157adb59 Mon Sep 17 00:00:00 2001 From: Jedi18 Date: Wed, 17 Feb 2021 19:51:35 +0530 Subject: [PATCH] added bool to choose between showing only rooms with aliases and all of the rooms --- src/RoomsModel.cpp | 23 +++++++++++++++-------- src/RoomsModel.h | 6 +++--- src/timeline/InputBar.cpp | 4 ++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/RoomsModel.cpp b/src/RoomsModel.cpp index 6ace8ef7..213d84df 100644 --- a/src/RoomsModel.cpp +++ b/src/RoomsModel.cpp @@ -3,18 +3,26 @@ #include "Cache_p.h" #include "CompletionModelRoles.h" -RoomsModel::RoomsModel(QObject *parent) +RoomsModel::RoomsModel(bool showOnlyRoomWithAliases, QObject *parent) : QAbstractListModel(parent) + , showOnlyRoomWithAliases_(showOnlyRoomWithAliases) { - rooms_ = cache::joinedRooms(); - roomInfos = cache::getRoomInfo(rooms_); + std::vector rooms_ = cache::joinedRooms(); + roomInfos = cache::getRoomInfo(rooms_); for (const auto &r : rooms_) { auto roomAliasesList = cache::client()->getRoomAliases(r); - if (roomAliasesList) { - roomAliases.push_back(QString::fromStdString(roomAliasesList->alias)); + if (showOnlyRoomWithAliases_) { + if (roomAliasesList) { + roomids.push_back(QString::fromStdString(r)); + roomAliases.push_back( + QString::fromStdString(roomAliasesList->alias)); + } + } else { roomids.push_back(QString::fromStdString(r)); + roomAliases.push_back( + roomAliasesList ? QString::fromStdString(roomAliasesList->alias) : ""); } } } @@ -43,14 +51,13 @@ RoomsModel::data(const QModelIndex &index, int role) const case Roles::RoomAlias: return roomAliases[index.row()]; case CompletionModel::SearchRole2: - return roomAliases[index.row()]; + case Roles::RoomName: + return QString::fromStdString(roomInfos.at(roomids[index.row()]).name); case Roles::AvatarUrl: return QString::fromStdString( roomInfos.at(roomids[index.row()]).avatar_url); case Roles::RoomID: return roomids[index.row()]; - case Roles::RoomName: - return QString::fromStdString(roomInfos.at(roomids[index.row()]).name); } } return {}; diff --git a/src/RoomsModel.h b/src/RoomsModel.h index 88cb5c68..0e006448 100644 --- a/src/RoomsModel.h +++ b/src/RoomsModel.h @@ -16,18 +16,18 @@ public: RoomName, }; - RoomsModel(QObject *parent = nullptr); + RoomsModel(bool showOnlyRoomWithAliases = false, QObject *parent = nullptr); QHash roleNames() const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override { (void)parent; - return (int)roomAliases.size(); + return (int)roomids.size(); } QVariant data(const QModelIndex &index, int role) const override; private: - std::vector rooms_; std::vector roomids; std::vector roomAliases; std::map roomInfos; + bool showOnlyRoomWithAliases_; }; diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 49fa5249..5ef38ac7 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -19,11 +19,11 @@ #include "MainWindow.h" #include "MatrixClient.h" #include "Olm.h" +#include "RoomsModel.h" #include "TimelineModel.h" #include "TimelineViewManager.h" #include "UserSettingsPage.h" #include "UsersModel.h" -#include "RoomsModel.h" #include "Utils.h" #include "dialogs/PreviewUploadOverlay.h" #include "emoji/EmojiModel.h" @@ -188,7 +188,7 @@ InputBar::completerFor(QString completerName) emojiModel->setParent(proxy); return proxy; } else if (completerName == "room") { - auto roomModel = new RoomsModel(); + auto roomModel = new RoomsModel(true); auto proxy = new CompletionProxyModel(roomModel); roomModel->setParent(proxy); return proxy;