summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-01-13 22:25:15 +0200
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-01-13 22:25:15 +0200
commitd31a08f1d59e9f70b0d2fc2a139efa52d1b03d75 (patch)
tree08fde5cad96c6db5fa1619df3a4fdcdf97349724 /src
parentMake some functions inline (diff)
downloadnheko-d31a08f1d59e9f70b0d2fc2a139efa52d1b03d75.tar.xz
Keep syncing regardless of connectivity (#93)
Diffstat (limited to 'src')
-rw-r--r--src/ChatPage.cc29
-rw-r--r--src/MatrixClient.cc2
2 files changed, 17 insertions, 14 deletions
diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index 4e57e280..9bb90134 100644
--- a/src/ChatPage.cc
+++ b/src/ChatPage.cc
@@ -43,7 +43,7 @@
 #include "timeline/TimelineViewManager.h"
 
 constexpr int MAX_INITIAL_SYNC_FAILURES = 5;
-constexpr int SYNC_RETRY_TIMEOUT        = 10000;
+constexpr int SYNC_RETRY_TIMEOUT        = 40000;
 
 ChatPage *ChatPage::instance_ = nullptr;
 
@@ -304,7 +304,6 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
                 client_->initialSync();
         });
         connect(client_.data(), &MatrixClient::syncCompleted, this, &ChatPage::syncCompleted);
-        connect(client_.data(), &MatrixClient::syncFailed, this, &ChatPage::syncFailed);
         connect(client_.data(),
                 &MatrixClient::getOwnProfileResponse,
                 this,
@@ -365,6 +364,17 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
                 }
         });
 
+        syncTimeoutTimer_ = new QTimer(this);
+        connect(syncTimeoutTimer_, &QTimer::timeout, this, [=]() {
+                if (client_->getHomeServer().isEmpty()) {
+                        syncTimeoutTimer_->stop();
+                        return;
+                }
+
+                qDebug() << "Sync took too long. Retrying...";
+                client_->sync();
+        });
+
         connect(communitiesList_,
                 &CommunitiesList::communityChanged,
                 this,
@@ -475,19 +485,10 @@ ChatPage::setOwnAvatar(const QPixmap &img)
 }
 
 void
-ChatPage::syncFailed(const QString &msg)
-{
-        // Stop if sync is not active. e.g user is logged out.
-        if (client_->getHomeServer().isEmpty())
-                return;
-
-        qWarning() << "Sync error:" << msg;
-        QTimer::singleShot(SYNC_RETRY_TIMEOUT, this, [=]() { client_->sync(); });
-}
-
-void
 ChatPage::syncCompleted(const mtx::responses::Sync &response)
 {
+        syncTimeoutTimer_->stop();
+
         updateJoinedRooms(response.rooms.join);
         removeLeftRooms(response.rooms.leave);
 
@@ -504,6 +505,8 @@ ChatPage::syncCompleted(const mtx::responses::Sync &response)
 
         client_->setNextBatchToken(nextBatchToken);
         client_->sync();
+
+        syncTimeoutTimer_->start(SYNC_RETRY_TIMEOUT);
 }
 
 void
diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc
index 53f6a32e..70a9bbf5 100644
--- a/src/MatrixClient.cc
+++ b/src/MatrixClient.cc
@@ -260,7 +260,7 @@ MatrixClient::sync() noexcept
                 int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
 
                 if (status == 0 || status >= 400) {
-                        emit syncFailed(reply->errorString());
+                        qDebug() << reply->errorString();
                         return;
                 }