diff --git a/include/ChatPage.h b/include/ChatPage.h index 5cd1c623..c9085848 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -128,7 +128,7 @@ private: template void updateUserMetadata(const std::vector &collection); - void retryInitialSync(); + void retryInitialSync(int status_code = -1); //! Update the room with the new notification count. void updateRoomNotificationCount(const QString &room_id, uint16_t notification_count); diff --git a/include/MatrixClient.h b/include/MatrixClient.h index 91e6db28..a433b095 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h @@ -147,7 +147,7 @@ signals: void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name); void getOwnCommunitiesResponse(const QList &own_communities); void initialSyncCompleted(const mtx::responses::Sync &response); - void initialSyncFailed(); + void initialSyncFailed(int status_code = -1); void syncCompleted(const mtx::responses::Sync &response); void syncFailed(const QString &msg); void joinFailed(const QString &msg); 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 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 diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index 544f58cb..5471e410 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -401,7 +401,7 @@ MatrixClient::initialSync() noexcept if (status == 0 || status >= 400) { qDebug() << "Error code received" << status; - emit initialSyncFailed(); + emit initialSyncFailed(status); return; }