Add pagination to space hierarchy cache
Add pagination to space hierarchy cache to ensure all rooms get cached.
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "spacehierarchycache.h"
|
#include "spacehierarchycache.h"
|
||||||
|
|
||||||
#include <Quotient/csapi/space_hierarchy.h>
|
|
||||||
#include <Quotient/qt_connection_util.h>
|
#include <Quotient/qt_connection_util.h>
|
||||||
|
|
||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
@@ -55,24 +54,44 @@ void SpaceHierarchyCache::populateSpaceHierarchy(const QString &spaceId)
|
|||||||
if (!m_connection) {
|
if (!m_connection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto job = m_connection->callApi<GetSpaceHierarchyJob>(spaceId);
|
|
||||||
|
m_nextBatchTokens[spaceId] = QString();
|
||||||
|
auto job = m_connection->callApi<GetSpaceHierarchyJob>(spaceId, none, none, none, *m_nextBatchTokens[spaceId]);
|
||||||
auto group = KConfigGroup(KSharedConfig::openStateConfig("SpaceHierarchy"_ls), "Cache"_ls);
|
auto group = KConfigGroup(KSharedConfig::openStateConfig("SpaceHierarchy"_ls), "Cache"_ls);
|
||||||
m_spaceHierarchy.insert(spaceId, group.readEntry(spaceId, QStringList()));
|
m_spaceHierarchy.insert(spaceId, group.readEntry(spaceId, QStringList()));
|
||||||
|
|
||||||
connect(job, &BaseJob::success, this, [this, job, spaceId]() {
|
connect(job, &BaseJob::success, this, [this, job, spaceId]() {
|
||||||
const auto rooms = job->rooms();
|
addBatch(spaceId, job);
|
||||||
QList<QString> roomList;
|
});
|
||||||
for (unsigned long i = 0; i < rooms.size(); ++i) {
|
}
|
||||||
for (const auto &state : rooms[i].childrenState) {
|
|
||||||
|
void SpaceHierarchyCache::addBatch(const QString &spaceId, Quotient::GetSpaceHierarchyJob *job)
|
||||||
|
{
|
||||||
|
const auto rooms = job->rooms();
|
||||||
|
QStringList roomList = m_spaceHierarchy[spaceId];
|
||||||
|
for (unsigned long i = 0; i < rooms.size(); ++i) {
|
||||||
|
for (const auto &state : rooms[i].childrenState) {
|
||||||
|
if (!roomList.contains(state->stateKey())) {
|
||||||
roomList.push_back(state->stateKey());
|
roomList.push_back(state->stateKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_spaceHierarchy.insert(spaceId, roomList);
|
}
|
||||||
Q_EMIT spaceHierarchyChanged();
|
m_spaceHierarchy.insert(spaceId, roomList);
|
||||||
auto group = KConfigGroup(KSharedConfig::openStateConfig("SpaceHierarchy"_ls), "Cache"_ls);
|
Q_EMIT spaceHierarchyChanged();
|
||||||
group.writeEntry(spaceId, roomList);
|
auto group = KConfigGroup(KSharedConfig::openStateConfig("SpaceHierarchy"_ls), "Cache"_ls);
|
||||||
group.sync();
|
group.writeEntry(spaceId, roomList);
|
||||||
});
|
group.sync();
|
||||||
|
|
||||||
|
const auto nextBatchToken = job->nextBatch();
|
||||||
|
if (!nextBatchToken.isEmpty() && nextBatchToken != *m_nextBatchTokens[spaceId]) {
|
||||||
|
*m_nextBatchTokens[spaceId] = nextBatchToken;
|
||||||
|
auto nextJob = m_connection->callApi<GetSpaceHierarchyJob>(spaceId, none, none, none, *m_nextBatchTokens[spaceId]);
|
||||||
|
connect(nextJob, &BaseJob::success, this, [this, nextJob, spaceId]() {
|
||||||
|
addBatch(spaceId, nextJob);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
m_nextBatchTokens[spaceId].reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpaceHierarchyCache::addSpaceToHierarchy(Quotient::Room *room)
|
void SpaceHierarchyCache::addSpaceToHierarchy(Quotient::Room *room)
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#include <Quotient/csapi/space_hierarchy.h>
|
||||||
|
|
||||||
#include "neochatconnection.h"
|
#include "neochatconnection.h"
|
||||||
|
|
||||||
namespace Quotient
|
namespace Quotient
|
||||||
@@ -110,6 +112,9 @@ private:
|
|||||||
QList<QString> m_activeSpaceRooms;
|
QList<QString> m_activeSpaceRooms;
|
||||||
QHash<QString, QList<QString>> m_spaceHierarchy;
|
QHash<QString, QList<QString>> m_spaceHierarchy;
|
||||||
void cacheSpaceHierarchy();
|
void cacheSpaceHierarchy();
|
||||||
|
|
||||||
|
QHash<QString, Quotient::Omittable<QString>> m_nextBatchTokens;
|
||||||
void populateSpaceHierarchy(const QString &spaceId);
|
void populateSpaceHierarchy(const QString &spaceId);
|
||||||
|
void addBatch(const QString &spaceId, Quotient::GetSpaceHierarchyJob *job);
|
||||||
NeoChatConnection *m_connection;
|
NeoChatConnection *m_connection;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user