aboutsummaryrefslogtreecommitdiff
path: root/connection.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-09-19 10:40:31 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-09-19 13:01:00 +0900
commit95e6ae003e3f5ed806bc7adf4e10713cd4e35d1f (patch)
tree5d146f38c0dddd453a938be8ec2e3c9c3c575ac4 /connection.h
parentd1fd237d8f917d393a2a8491abc1554abd398085 (diff)
downloadlibquotient-95e6ae003e3f5ed806bc7adf4e10713cd4e35d1f.tar.gz
libquotient-95e6ae003e3f5ed806bc7adf4e10713cd4e35d1f.zip
Connection::cacheState property, load/saveState() tweaks and fixes
The property controls whether or not the rooms state is cached: if it's off, loadState() and saveState() become no-ops. Other changes: * loadState/saveState properly deal with rooms in Invite state (this is not quite relevant to the current branch but very much is in the light of a concurrent kitsune-invite-kick PR); * Profile loadState/saveState (because dumping and especially parsing JSON takes time); * Use QJsonDocument::Compact layout, it's about 3 times smaller and quicker to parse than Indented, and we really don't care about the cache being human-friendly; * Have a default path for the state cache, based on the connection's user id.
Diffstat (limited to 'connection.h')
-rw-r--r--connection.h40
1 files changed, 36 insertions, 4 deletions
diff --git a/connection.h b/connection.h
index ad161d7c..bf50d7d3 100644
--- a/connection.h
+++ b/connection.h
@@ -39,6 +39,11 @@ namespace QMatrixClient
class Connection: public QObject {
Q_OBJECT
+
+ /** Whether or not the rooms state should be cached locally
+ * \sa loadState(), saveState()
+ */
+ Q_PROPERTY(bool cacheState READ cacheState WRITE setCacheState NOTIFY cacheStateChanged)
public:
explicit Connection(const QUrl& server, QObject* parent = nullptr);
Connection();
@@ -86,10 +91,35 @@ namespace QMatrixClient
/**
* Call this before first sync to load from previously saved file.
- * Uses QUrl to be QML-friendly.
- */
- Q_INVOKABLE void loadState(const QUrl &fromFile);
- Q_INVOKABLE void saveState(const QUrl &toFile);
+ *
+ * \param fromFile A local path to read the state from. Uses QUrl
+ * to be QML-friendly. Empty parameter means using a path
+ * defined by stateCachePath().
+ */
+ Q_INVOKABLE void loadState(const QUrl &fromFile = {});
+ /**
+ * This method saves the current state of rooms (but not messages
+ * in them) to a local cache file, so that it could be loaded by
+ * loadState() on a next run of the client.
+ *
+ * \param toFile A local path to save the state to. Uses QUrl to be
+ * QML-friendly. Empty parameter means using a path defined by
+ * stateCachePath().
+ */
+ Q_INVOKABLE void saveState(const QUrl &toFile = {}) const;
+
+ /**
+ * The default path to store the cached room state, defined as
+ * follows:
+ * QStandardPaths::writeableLocation(QStandardPaths::CacheLocation) + _safeUserId + "_state.json"
+ * where `_safeUserId` is userId() with `:` (colon) replaced with
+ * `_` (underscore)
+ * /see loadState(), saveState()
+ */
+ Q_INVOKABLE QString stateCachePath() const;
+
+ bool cacheState() const;
+ void setCacheState(bool newValue);
template <typename JobT, typename... JobArgTs>
JobT* callApi(JobArgTs... jobArgs) const
@@ -120,6 +150,8 @@ namespace QMatrixClient
void syncError(QString error);
//void jobError(BaseJob* job);
+ void cacheStateChanged();
+
protected:
/**
* @brief Access the underlying ConnectionData class