Show spaces horizontal bar
### Summary This merge request adds a horizontal bar at top of room list, which shows spaces. By clicking on a space, user can filter out rooms belonging only to that specific space. ### Pending/ Help needed #### Segfault when loading active connection on startup Refer `void SortFilterRoomListModel::cacheSpaceHierarchy()` ([link](8c372800d7 (b969e462c30df43ef3714ea441948d8d8027f6a0_117_126))) in `src/sortfilterroomlistmodel.cpp`. On [line 129](8c372800d7 (b969e462c30df43ef3714ea441948d8d8027f6a0_117_129)), I have called `connection->allRooms()`, which segfaults if the active connection hasn't been loaded yet. Is there a way to ensure that `Controller::instance().activeConnection()` on line 128 waits till connection is loaded? #### Avatars Avatars on space horizontal bar aren't aligned to vertical middle. I'll need help with that. Using the code below doesn't help with padding ```qml delegate: QQC2.Control { topPadding: 10 contentItem: Kirigami.Avatar { ..... } } ``` This complains about uninitialized properties in `Kirigami.Avatar`. (`id`, `currentRoom`, `avatar`, `index` are properties utilized during run time) After we get around these two issue, this MR will be ready from my side.
This commit is contained in:
72
src/spacehierarchycache.cpp
Normal file
72
src/spacehierarchycache.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
// SPDX-FileCopyrightText: 2022 Snehit Sah <hi@snehit.dev>
|
||||
// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||
|
||||
#include "spacehierarchycache.h"
|
||||
|
||||
#include "controller.h"
|
||||
#ifdef QUOTIENT_07
|
||||
#include "csapi/space_hierarchy.h"
|
||||
#endif
|
||||
#include "neochatroom.h"
|
||||
|
||||
SpaceHierarchyCache::SpaceHierarchyCache(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
cacheSpaceHierarchy();
|
||||
connect(&Controller::instance(), &Controller::activeConnectionChanged, this, [this]() {
|
||||
cacheSpaceHierarchy();
|
||||
});
|
||||
}
|
||||
|
||||
void SpaceHierarchyCache::cacheSpaceHierarchy()
|
||||
{
|
||||
#ifdef QUOTIENT_07
|
||||
auto connection = Controller::instance().activeConnection();
|
||||
if (!connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto roomList = connection->allRooms();
|
||||
for (const auto &room : roomList) {
|
||||
const auto neoChatRoom = static_cast<NeoChatRoom *>(room);
|
||||
if (neoChatRoom->isSpace()) {
|
||||
populateSpaceHierarchy(neoChatRoom->id());
|
||||
} else {
|
||||
connect(neoChatRoom, &Room::baseStateLoaded, neoChatRoom, [this, neoChatRoom]() {
|
||||
if (neoChatRoom->isSpace()) {
|
||||
populateSpaceHierarchy(neoChatRoom->id());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SpaceHierarchyCache::populateSpaceHierarchy(const QString &spaceId)
|
||||
{
|
||||
auto connection = Controller::instance().activeConnection();
|
||||
if (!connection) {
|
||||
return;
|
||||
}
|
||||
#ifdef QUOTIENT_07
|
||||
GetSpaceHierarchyJob *job = connection->callApi<GetSpaceHierarchyJob>(spaceId);
|
||||
|
||||
connect(job, &BaseJob::success, this, [this, job, spaceId]() {
|
||||
const auto rooms = job->rooms();
|
||||
QVector<QString> roomList;
|
||||
for (unsigned long i = 0; i < rooms.size(); ++i) {
|
||||
roomList.push_back(rooms.at(i).roomId);
|
||||
}
|
||||
m_spaceHierarchy.insert(spaceId, roomList);
|
||||
Q_EMIT spaceHierarchyChanged();
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
QVector<QString> SpaceHierarchyCache::getRoomListForSpace(const QString &spaceId, bool updateCache)
|
||||
{
|
||||
if (updateCache) {
|
||||
populateSpaceHierarchy(spaceId);
|
||||
}
|
||||
return m_spaceHierarchy[spaceId];
|
||||
}
|
||||
Reference in New Issue
Block a user