summary refs log tree commit diff
path: root/include
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-01-21 21:43:21 +0200
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-01-21 21:43:21 +0200
commitc59cd0e80bcbf1e37b7d6b021275d4c8f90f1914 (patch)
treee809690d042aca74c620b09f4a9f471cbe2240a3 /include
parentRefactor avatar fetching in one function (diff)
downloadnheko-c59cd0e80bcbf1e37b7d6b021275d4c8f90f1914.tar.xz
Load the initial cache data without blocking the UI
Diffstat (limited to 'include')
-rw-r--r--include/Cache.h14
-rw-r--r--include/RoomState.h2
2 files changed, 12 insertions, 4 deletions
diff --git a/include/Cache.h b/include/Cache.h
index 7a626e12..e8d797dd 100644
--- a/include/Cache.h
+++ b/include/Cache.h
@@ -18,11 +18,12 @@
 #pragma once
 
 #include <QDir>
+#include <QMap>
 #include <json.hpp>
 #include <lmdb++.h>
 #include <mtx/responses.hpp>
 
-class RoomState;
+#include "RoomState.h"
 
 //! Used to uniquely identify a list of read receipts.
 struct ReadReceiptKey
@@ -44,17 +45,19 @@ from_json(const json &j, ReadReceiptKey &key)
         key.room_id  = j.at("room_id").get<std::string>();
 }
 
-class Cache
+class Cache : public QObject
 {
+        Q_OBJECT
+
 public:
-        Cache(const QString &userId);
+        Cache(const QString &userId, QObject *parent = nullptr);
 
         void setState(const QString &nextBatchToken,
                       const QMap<QString, QSharedPointer<RoomState>> &states);
         bool isInitialized() const;
 
         QString nextBatchToken() const;
-        QMap<QString, RoomState> states();
+        void states();
 
         using Invites = std::map<std::string, mtx::responses::InvitedRoom>;
         Invites invites();
@@ -86,6 +89,9 @@ public:
         QByteArray image(const QString &url) const;
         void saveImage(const QString &url, const QByteArray &data);
 
+signals:
+        void statesLoaded(QMap<QString, RoomState> states);
+
 private:
         void setNextBatchToken(lmdb::txn &txn, const QString &token);
         void insertRoomState(lmdb::txn &txn,
diff --git a/include/RoomState.h b/include/RoomState.h
index 0e91410c..6f335263 100644
--- a/include/RoomState.h
+++ b/include/RoomState.h
@@ -77,6 +77,8 @@ private:
         QString userAvatar_;
 };
 
+Q_DECLARE_METATYPE(RoomState)
+
 template<class Collection>
 void
 RoomState::updateFromEvents(const std::vector<Collection> &collection)