aboutsummaryrefslogtreecommitdiff
path: root/lib/connection.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-02-11 09:10:55 +0900
committerGitHub <noreply@github.com>2019-02-11 09:10:55 +0900
commite98ec84ab31b2dc656597ac5c87a8299b6c8aed8 (patch)
treee26b828c55ea563e3486167b53a12959d7b35565 /lib/connection.cpp
parentf438d37b169965ee0a9937b5178560a653f1197b (diff)
parent73c836239bfa35713ad76d5e205ce2f2dceffffd (diff)
downloadlibquotient-e98ec84ab31b2dc656597ac5c87a8299b6c8aed8.tar.gz
libquotient-e98ec84ab31b2dc656597ac5c87a8299b6c8aed8.zip
Merge pull request #274 from a-andreyev/aa13q-loop-logic
Connection: additional infinite sync loop logic
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r--lib/connection.cpp13
1 files changed, 13 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())