diff options
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r-- | lib/connection.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index c582cf94..982145f7 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -133,6 +133,8 @@ Connection::Connection(const QUrl& server, QObject* parent) , d(std::make_unique<Private>(std::make_unique<ConnectionData>(server))) { d->q = this; // All d initialization should occur before this line + // sync loop: + connect(this, &Connection::syncDone, this, &Connection::getNewEvents); } Connection::Connection(QObject* parent) @@ -250,7 +252,7 @@ void Connection::Private::connectWithToken(const QString& user, << "by user" << userId << "from device" << deviceId; emit q->stateChanged(); emit q->connected(); - + q->sync(); // initial sync after connection } void Connection::checkAndConnect(const QString& userId, @@ -406,6 +408,15 @@ void Connection::onSyncSuccess(SyncData &&data, bool fromCache) { } } +void Connection::getNewEvents() +{ + // Borrowed the logic from Quiark's code in Tensor + // to cache not too aggressively and not on the first sync. + if (++_saveStateCounter % 17 == 2) + saveState(); + sync(30*1000); +} + void Connection::stopSync() { if (d->syncJob) |