Load the initial cache data without blocking the UI
This commit is contained in:
parent
c123bada94
commit
c59cd0e80b
5 changed files with 52 additions and 37 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ private:
|
|||
QString userAvatar_;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(RoomState)
|
||||
|
||||
template<class Collection>
|
||||
void
|
||||
RoomState::updateFromEvents(const std::vector<Collection> &collection)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue