Initially load space hierarchy from cache
This brings us to the final result faster after starting the client, which leads to a nicer UX. It will still miss rooms if the room the "current" room is some descendant from the room in the space child event and the user has not joined all rooms between them.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <Quotient/csapi/space_hierarchy.h>
|
||||
#include <Quotient/qt_connection_util.h>
|
||||
#include <Quotient/quotient_common.h>
|
||||
|
||||
#include <KConfigGroup>
|
||||
#include <KSharedConfig>
|
||||
@@ -50,11 +51,33 @@ void SpaceHierarchyCache::cacheSpaceHierarchy()
|
||||
}
|
||||
}
|
||||
|
||||
void SpaceHierarchyCache::populateFromState(const QString &spaceId, const QString &rootId)
|
||||
{
|
||||
if (const auto &room = m_connection->room(spaceId)) {
|
||||
for (const auto &event : room->currentState().eventsOfType("m.space.child"_ls)) {
|
||||
if (const auto &child = m_connection->room(event->stateKey())) {
|
||||
m_spaceHierarchy[rootId] += event->stateKey();
|
||||
auto successor = child;
|
||||
do {
|
||||
m_spaceHierarchy[rootId] += successor->id();
|
||||
} while ((successor = successor->successor(JoinState::Join)));
|
||||
if (dynamic_cast<NeoChatRoom *>(child)->isSpace()) {
|
||||
populateFromState(child->id(), rootId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Q_EMIT spaceHierarchyChanged();
|
||||
}
|
||||
|
||||
void SpaceHierarchyCache::populateSpaceHierarchy(const QString &spaceId)
|
||||
{
|
||||
if (!m_connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
populateFromState(spaceId, spaceId);
|
||||
|
||||
auto job = m_connection->callApi<GetSpaceHierarchyJob>(spaceId);
|
||||
|
||||
connect(job, &BaseJob::success, this, [this, job, spaceId]() {
|
||||
|
||||
@@ -102,6 +102,8 @@ private Q_SLOTS:
|
||||
private:
|
||||
explicit SpaceHierarchyCache(QObject *parent = nullptr);
|
||||
|
||||
void populateFromState(const QString &roomId, const QString &rootId);
|
||||
|
||||
QList<QString> m_activeSpaceRooms;
|
||||
QHash<QString, QList<QString>> m_spaceHierarchy;
|
||||
void cacheSpaceHierarchy();
|
||||
|
||||
Reference in New Issue
Block a user