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 "spacehierarchycache.h"
|
||||||
|
|
||||||
#include "controller.h"
|
|
||||||
#ifdef QUOTIENT_07
|
#ifdef QUOTIENT_07
|
||||||
#include <csapi/space_hierarchy.h>
|
#include <csapi/space_hierarchy.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <qt_connection_util.h>
|
||||||
|
|
||||||
|
#include "controller.h"
|
||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
|
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
@@ -17,6 +19,8 @@ SpaceHierarchyCache::SpaceHierarchyCache(QObject *parent)
|
|||||||
cacheSpaceHierarchy();
|
cacheSpaceHierarchy();
|
||||||
connect(&Controller::instance(), &Controller::activeConnectionChanged, this, [this]() {
|
connect(&Controller::instance(), &Controller::activeConnectionChanged, this, [this]() {
|
||||||
cacheSpaceHierarchy();
|
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
|
#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)
|
QVector<QString> &SpaceHierarchyCache::getRoomListForSpace(const QString &spaceId, bool updateCache)
|
||||||
{
|
{
|
||||||
if (updateCache) {
|
if (updateCache) {
|
||||||
|
|||||||
@@ -8,6 +8,11 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
namespace Quotient
|
||||||
|
{
|
||||||
|
class Room;
|
||||||
|
}
|
||||||
|
|
||||||
class SpaceHierarchyCache : public QObject
|
class SpaceHierarchyCache : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -24,6 +29,10 @@ public:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void spaceHierarchyChanged();
|
void spaceHierarchyChanged();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void addSpaceToHierarchy(Quotient::Room *room);
|
||||||
|
void removeSpaceFromHierarchy(Quotient::Room *room);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit SpaceHierarchyCache(QObject *parent = nullptr);
|
explicit SpaceHierarchyCache(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user