summary refs log tree commit diff
path: root/src/ChatPage.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-03-04 14:49:15 +0200
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-03-04 14:49:15 +0200
commit0f62cba49853b644405fadefaf8b87c32bc4b9a1 (patch)
tree9123367a70913f7849696dcc0a3ae814a2d0c977 /src/ChatPage.cc
parentBump version (diff)
downloadnheko-0f62cba49853b644405fadefaf8b87c32bc4b9a1.tar.xz
Retry initial sync only on specific errors
fixes #233
fixes #89
Diffstat (limited to 'src/ChatPage.cc')
-rw-r--r--src/ChatPage.cc21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index 93ae562e..571ac67a 100644
--- a/src/ChatPage.cc
+++ b/src/ChatPage.cc
@@ -361,7 +361,7 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
         });
 
         initialSyncTimer_ = new QTimer(this);
-        connect(initialSyncTimer_, &QTimer::timeout, this, &ChatPage::retryInitialSync);
+        connect(initialSyncTimer_, &QTimer::timeout, this, [this]() { retryInitialSync(); });
 
         syncTimeoutTimer_ = new QTimer(this);
         connect(syncTimeoutTimer_, &QTimer::timeout, this, [this]() {
@@ -965,19 +965,30 @@ ChatPage::setGroupViewState(bool isEnabled)
 }
 
 void
-ChatPage::retryInitialSync()
+ChatPage::retryInitialSync(int status_code)
 {
         initialSyncTimer_->stop();
 
         if (client_->getHomeServer().isEmpty()) {
                 deleteConfigs();
+                resetUI();
+                emit showLoginPage("Sync error. Please try again.");
                 return;
         }
 
-        qWarning() << "Retrying initial sync";
+        // Retry on Bad-Gateway & Gateway-Timeout errors
+        if (status_code == -1 || status_code == 504 || status_code == 502 || status_code == 524) {
+                qWarning() << "retrying initial sync";
 
-        client_->initialSync();
-        initialSyncTimer_->start(INITIAL_SYNC_RETRY_TIMEOUT);
+                client_->initialSync();
+                initialSyncTimer_->start(INITIAL_SYNC_RETRY_TIMEOUT);
+        } else {
+                // Drop into the login screen.
+                deleteConfigs();
+                resetUI();
+
+                emit showLoginPage(QString("Sync error %1. Please try again.").arg(status_code));
+        }
 }
 
 void