added bool to choose between showing only rooms with aliases and all of the rooms
This commit is contained in:
parent
8aadde7885
commit
0b6c82dfff
@ -3,18 +3,26 @@
|
|||||||
#include "Cache_p.h"
|
#include "Cache_p.h"
|
||||||
#include "CompletionModelRoles.h"
|
#include "CompletionModelRoles.h"
|
||||||
|
|
||||||
RoomsModel::RoomsModel(QObject *parent)
|
RoomsModel::RoomsModel(bool showOnlyRoomWithAliases, QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
|
, showOnlyRoomWithAliases_(showOnlyRoomWithAliases)
|
||||||
{
|
{
|
||||||
rooms_ = cache::joinedRooms();
|
std::vector<std::string> rooms_ = cache::joinedRooms();
|
||||||
roomInfos = cache::getRoomInfo(rooms_);
|
roomInfos = cache::getRoomInfo(rooms_);
|
||||||
|
|
||||||
for (const auto &r : rooms_) {
|
for (const auto &r : rooms_) {
|
||||||
auto roomAliasesList = cache::client()->getRoomAliases(r);
|
auto roomAliasesList = cache::client()->getRoomAliases(r);
|
||||||
|
|
||||||
|
if (showOnlyRoomWithAliases_) {
|
||||||
if (roomAliasesList) {
|
if (roomAliasesList) {
|
||||||
roomAliases.push_back(QString::fromStdString(roomAliasesList->alias));
|
|
||||||
roomids.push_back(QString::fromStdString(r));
|
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:
|
case Roles::RoomAlias:
|
||||||
return roomAliases[index.row()];
|
return roomAliases[index.row()];
|
||||||
case CompletionModel::SearchRole2:
|
case CompletionModel::SearchRole2:
|
||||||
return roomAliases[index.row()];
|
case Roles::RoomName:
|
||||||
|
return QString::fromStdString(roomInfos.at(roomids[index.row()]).name);
|
||||||
case Roles::AvatarUrl:
|
case Roles::AvatarUrl:
|
||||||
return QString::fromStdString(
|
return QString::fromStdString(
|
||||||
roomInfos.at(roomids[index.row()]).avatar_url);
|
roomInfos.at(roomids[index.row()]).avatar_url);
|
||||||
case Roles::RoomID:
|
case Roles::RoomID:
|
||||||
return roomids[index.row()];
|
return roomids[index.row()];
|
||||||
case Roles::RoomName:
|
|
||||||
return QString::fromStdString(roomInfos.at(roomids[index.row()]).name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
@ -16,18 +16,18 @@ public:
|
|||||||
RoomName,
|
RoomName,
|
||||||
};
|
};
|
||||||
|
|
||||||
RoomsModel(QObject *parent = nullptr);
|
RoomsModel(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
|
||||||
{
|
{
|
||||||
(void)parent;
|
(void)parent;
|
||||||
return (int)roomAliases.size();
|
return (int)roomids.size();
|
||||||
}
|
}
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> rooms_;
|
|
||||||
std::vector<QString> roomids;
|
std::vector<QString> roomids;
|
||||||
std::vector<QString> roomAliases;
|
std::vector<QString> roomAliases;
|
||||||
std::map<QString, RoomInfo> roomInfos;
|
std::map<QString, RoomInfo> roomInfos;
|
||||||
|
bool showOnlyRoomWithAliases_;
|
||||||
};
|
};
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "Olm.h"
|
#include "Olm.h"
|
||||||
|
#include "RoomsModel.h"
|
||||||
#include "TimelineModel.h"
|
#include "TimelineModel.h"
|
||||||
#include "TimelineViewManager.h"
|
#include "TimelineViewManager.h"
|
||||||
#include "UserSettingsPage.h"
|
#include "UserSettingsPage.h"
|
||||||
#include "UsersModel.h"
|
#include "UsersModel.h"
|
||||||
#include "RoomsModel.h"
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "dialogs/PreviewUploadOverlay.h"
|
#include "dialogs/PreviewUploadOverlay.h"
|
||||||
#include "emoji/EmojiModel.h"
|
#include "emoji/EmojiModel.h"
|
||||||
@ -188,7 +188,7 @@ InputBar::completerFor(QString completerName)
|
|||||||
emojiModel->setParent(proxy);
|
emojiModel->setParent(proxy);
|
||||||
return proxy;
|
return proxy;
|
||||||
} else if (completerName == "room") {
|
} else if (completerName == "room") {
|
||||||
auto roomModel = new RoomsModel();
|
auto roomModel = new RoomsModel(true);
|
||||||
auto proxy = new CompletionProxyModel(roomModel);
|
auto proxy = new CompletionProxyModel(roomModel);
|
||||||
roomModel->setParent(proxy);
|
roomModel->setParent(proxy);
|
||||||
return proxy;
|
return proxy;
|
||||||
|
Loading…
Reference in New Issue
Block a user