Update space heirarchy cache
Add functions to update the space heirarchy cache when a new space is added or removed.
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
|
||||
#include "spacehierarchycache.h"
|
||||
|
||||
#include "controller.h"
|
||||
#ifdef QUOTIENT_07
|
||||
#include <csapi/space_hierarchy.h>
|
||||
#endif
|
||||
#include <qt_connection_util.h>
|
||||
|
||||
#include "controller.h"
|
||||
#include "neochatroom.h"
|
||||
|
||||
using namespace Quotient;
|
||||
@@ -17,6 +19,8 @@ SpaceHierarchyCache::SpaceHierarchyCache(QObject *parent)
|
||||
cacheSpaceHierarchy();
|
||||
connect(&Controller::instance(), &Controller::activeConnectionChanged, this, [this]() {
|
||||
cacheSpaceHierarchy();
|
||||
connect(Controller::instance().activeConnection(), &Connection::joinedRoom, this, &SpaceHierarchyCache::addSpaceToHierarchy);
|
||||
connect(Controller::instance().activeConnection(), &Connection::aboutToDeleteRoom, this, &SpaceHierarchyCache::removeSpaceFromHierarchy);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,6 +72,24 @@ void SpaceHierarchyCache::populateSpaceHierarchy(const QString &spaceId)
|
||||
#endif
|
||||
}
|
||||
|
||||
void SpaceHierarchyCache::addSpaceToHierarchy(Quotient::Room *room)
|
||||
{
|
||||
connectSingleShot(room, &Quotient::Room::baseStateLoaded, this, [this, room]() {
|
||||
const auto neoChatRoom = static_cast<NeoChatRoom *>(room);
|
||||
if (neoChatRoom->isSpace()) {
|
||||
populateSpaceHierarchy(neoChatRoom->id());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void SpaceHierarchyCache::removeSpaceFromHierarchy(Quotient::Room *room)
|
||||
{
|
||||
const auto neoChatRoom = static_cast<NeoChatRoom *>(room);
|
||||
if (neoChatRoom->isSpace()) {
|
||||
m_spaceHierarchy.remove(neoChatRoom->id());
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QString> &SpaceHierarchyCache::getRoomListForSpace(const QString &spaceId, bool updateCache)
|
||||
{
|
||||
if (updateCache) {
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
namespace Quotient
|
||||
{
|
||||
class Room;
|
||||
}
|
||||
|
||||
class SpaceHierarchyCache : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -24,6 +29,10 @@ public:
|
||||
Q_SIGNALS:
|
||||
void spaceHierarchyChanged();
|
||||
|
||||
private Q_SLOTS:
|
||||
void addSpaceToHierarchy(Quotient::Room *room);
|
||||
void removeSpaceFromHierarchy(Quotient::Room *room);
|
||||
|
||||
private:
|
||||
explicit SpaceHierarchyCache(QObject *parent = nullptr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user