Refactor and clean up spaces
This commit is contained in:
@@ -178,7 +178,6 @@ int main(int argc, char *argv[])
|
||||
Login *login = new Login();
|
||||
ChatBoxHelper chatBoxHelper;
|
||||
UrlHelper urlHelper;
|
||||
SpaceHierarchyCache spaceHierarchyCache;
|
||||
|
||||
#ifdef HAVE_COLORSCHEME
|
||||
ColorSchemer colorScheme;
|
||||
@@ -199,7 +198,7 @@ int main(int argc, char *argv[])
|
||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "EmojiModel", new EmojiModel(&app));
|
||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CommandModel", new CommandModel(&app));
|
||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::AccountRegistry::instance());
|
||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "SpaceHierarchyCache", &spaceHierarchyCache);
|
||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "SpaceHierarchyCache", &SpaceHierarchyCache::instance());
|
||||
qmlRegisterType<ActionsHandler>("org.kde.neochat", 1, 0, "ActionsHandler");
|
||||
qmlRegisterType<ChatBoxHelper>("org.kde.neochat", 1, 0, "ChatBoxHelper");
|
||||
qmlRegisterType<ChatDocumentHandler>("org.kde.neochat", 1, 0, "ChatDocumentHandler");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "sortfilterroomlistmodel.h"
|
||||
|
||||
#include "roomlistmodel.h"
|
||||
#include "spacehierarchycache.h"
|
||||
|
||||
SortFilterRoomListModel::SortFilterRoomListModel(QObject *parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
@@ -81,18 +82,23 @@ bool SortFilterRoomListModel::filterAcceptsRow(int source_row, const QModelIndex
|
||||
&& sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::JoinStateRole).toString() != "upgraded"
|
||||
&& sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IsSpaceRole).toBool() == false;
|
||||
|
||||
if (m_activeSpaceRooms.empty())
|
||||
if (m_activeSpaceId.isEmpty()) {
|
||||
return acceptRoom;
|
||||
else
|
||||
return std::find(m_activeSpaceRooms.begin(),
|
||||
m_activeSpaceRooms.end(),
|
||||
sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IdRole).toString())
|
||||
!= m_activeSpaceRooms.end()
|
||||
} else {
|
||||
const auto &rooms = SpaceHierarchyCache::instance().getRoomListForSpace(m_activeSpaceId, false);
|
||||
return std::find(rooms.begin(), rooms.end(), sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IdRole).toString()) != rooms.end()
|
||||
&& acceptRoom;
|
||||
}
|
||||
}
|
||||
|
||||
void SortFilterRoomListModel::setActiveSpaceRooms(QVector<QString> activeSpaceRooms)
|
||||
QString SortFilterRoomListModel::activeSpaceId() const
|
||||
{
|
||||
this->m_activeSpaceRooms = activeSpaceRooms;
|
||||
return m_activeSpaceId;
|
||||
}
|
||||
|
||||
void SortFilterRoomListModel::setActiveSpaceId(const QString &spaceId)
|
||||
{
|
||||
m_activeSpaceId = spaceId;
|
||||
Q_EMIT activeSpaceIdChanged();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class SortFilterRoomListModel : public QSortFilterProxyModel
|
||||
|
||||
Q_PROPERTY(RoomSortOrder roomSortOrder READ roomSortOrder WRITE setRoomSortOrder NOTIFY roomSortOrderChanged)
|
||||
Q_PROPERTY(QString filterText READ filterText READ filterText WRITE setFilterText NOTIFY filterTextChanged)
|
||||
Q_PROPERTY(QVector<QString> activeSpaceRooms WRITE setActiveSpaceRooms)
|
||||
Q_PROPERTY(QString activeSpaceId READ activeSpaceId WRITE setActiveSpaceId NOTIFY activeSpaceIdChanged)
|
||||
|
||||
public:
|
||||
enum RoomSortOrder {
|
||||
@@ -31,7 +31,8 @@ public:
|
||||
|
||||
[[nodiscard]] bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
|
||||
|
||||
Q_INVOKABLE void setActiveSpaceRooms(QVector<QString> activeSpaceRooms);
|
||||
QString activeSpaceId() const;
|
||||
void setActiveSpaceId(const QString &spaceId);
|
||||
|
||||
protected:
|
||||
[[nodiscard]] bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
||||
@@ -39,9 +40,10 @@ protected:
|
||||
Q_SIGNALS:
|
||||
void roomSortOrderChanged();
|
||||
void filterTextChanged();
|
||||
void activeSpaceIdChanged();
|
||||
|
||||
private:
|
||||
RoomSortOrder m_sortOrder = Categories;
|
||||
QString m_filterText;
|
||||
QVector<QString> m_activeSpaceRooms;
|
||||
QString m_activeSpaceId;
|
||||
};
|
||||
|
||||
@@ -66,7 +66,7 @@ void SpaceHierarchyCache::populateSpaceHierarchy(const QString &spaceId)
|
||||
#endif
|
||||
}
|
||||
|
||||
QVector<QString> SpaceHierarchyCache::getRoomListForSpace(const QString &spaceId, bool updateCache)
|
||||
QVector<QString> &SpaceHierarchyCache::getRoomListForSpace(const QString &spaceId, bool updateCache)
|
||||
{
|
||||
if (updateCache) {
|
||||
populateSpaceHierarchy(spaceId);
|
||||
|
||||
@@ -13,14 +13,20 @@ class SpaceHierarchyCache : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SpaceHierarchyCache(QObject *parent = nullptr);
|
||||
static SpaceHierarchyCache &instance()
|
||||
{
|
||||
static SpaceHierarchyCache _instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
[[nodiscard]] Q_INVOKABLE QVector<QString> getRoomListForSpace(const QString &spaceId, bool updateCache);
|
||||
[[nodiscard]] QVector<QString> &getRoomListForSpace(const QString &spaceId, bool updateCache);
|
||||
|
||||
Q_SIGNALS:
|
||||
void spaceHierarchyChanged();
|
||||
|
||||
private:
|
||||
explicit SpaceHierarchyCache(QObject *parent = nullptr);
|
||||
|
||||
QVector<QString> m_activeSpaceRooms;
|
||||
QHash<QString, QVector<QString>> m_spaceHierarchy;
|
||||
void cacheSpaceHierarchy();
|
||||
|
||||
Reference in New Issue
Block a user