diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connection.cpp | 13 | ||||
-rw-r--r-- | lib/connection.h | 5 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index c582cf94..63b0a31d 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -90,6 +90,7 @@ class Connection::Private DirectChatUsersMap directChatUsers; std::unordered_map<QString, EventPtr> accountData; QString userId; + int syncLoopTimeout = -1; SyncJob* syncJob = nullptr; @@ -230,6 +231,11 @@ void Connection::doConnectToServer(const QString& user, const QString& password, }); } +void Connection::syncLoopIteration() +{ + sync(d->syncLoopTimeout); +} + void Connection::connectWithToken(const QString& userId, const QString& accessToken, const QString& deviceId) @@ -319,6 +325,13 @@ void Connection::sync(int timeout) }); } +void Connection::syncLoop(int timeout) +{ + d->syncLoopTimeout = timeout; + connect(this, &Connection::syncDone, this, &Connection::syncLoopIteration); + syncLoopIteration(); // initial sync to start the loop +} + void Connection::onSyncSuccess(SyncData &&data, bool fromCache) { d->data->setLastEvent(data.nextBatch()); for (auto&& roomData: data.takeRoomData()) diff --git a/lib/connection.h b/lib/connection.h index 9e4121f4..45b691e1 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -371,6 +371,8 @@ namespace QMatrixClient void logout(); void sync(int timeout = -1); + void syncLoop(int timeout = -1); + void stopSync(); QString nextBatchToken() const; @@ -679,6 +681,9 @@ namespace QMatrixClient */ void onSyncSuccess(SyncData &&data, bool fromCache = false); + protected slots: + void syncLoopIteration(); + private: class Private; std::unique_ptr<Private> d; |