Retry initial sync only on specific errors

fixes #233
fixes #89
This commit is contained in:
Konstantinos Sideris 2018-03-04 14:49:15 +02:00
parent 7fc33a71fd
commit 0f62cba498
4 changed files with 19 additions and 8 deletions

View File

@ -128,7 +128,7 @@ private:
template<class Collection> template<class Collection>
void updateUserMetadata(const std::vector<Collection> &collection); void updateUserMetadata(const std::vector<Collection> &collection);
void retryInitialSync(); void retryInitialSync(int status_code = -1);
//! Update the room with the new notification count. //! Update the room with the new notification count.
void updateRoomNotificationCount(const QString &room_id, uint16_t notification_count); void updateRoomNotificationCount(const QString &room_id, uint16_t notification_count);

View File

@ -147,7 +147,7 @@ signals:
void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name); void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name);
void getOwnCommunitiesResponse(const QList<QString> &own_communities); void getOwnCommunitiesResponse(const QList<QString> &own_communities);
void initialSyncCompleted(const mtx::responses::Sync &response); void initialSyncCompleted(const mtx::responses::Sync &response);
void initialSyncFailed(); void initialSyncFailed(int status_code = -1);
void syncCompleted(const mtx::responses::Sync &response); void syncCompleted(const mtx::responses::Sync &response);
void syncFailed(const QString &msg); void syncFailed(const QString &msg);
void joinFailed(const QString &msg); void joinFailed(const QString &msg);

View File

@ -361,7 +361,7 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
}); });
initialSyncTimer_ = new QTimer(this); initialSyncTimer_ = new QTimer(this);
connect(initialSyncTimer_, &QTimer::timeout, this, &ChatPage::retryInitialSync); connect(initialSyncTimer_, &QTimer::timeout, this, [this]() { retryInitialSync(); });
syncTimeoutTimer_ = new QTimer(this); syncTimeoutTimer_ = new QTimer(this);
connect(syncTimeoutTimer_, &QTimer::timeout, this, [this]() { connect(syncTimeoutTimer_, &QTimer::timeout, this, [this]() {
@ -965,19 +965,30 @@ ChatPage::setGroupViewState(bool isEnabled)
} }
void void
ChatPage::retryInitialSync() ChatPage::retryInitialSync(int status_code)
{ {
initialSyncTimer_->stop(); initialSyncTimer_->stop();
if (client_->getHomeServer().isEmpty()) { if (client_->getHomeServer().isEmpty()) {
deleteConfigs(); deleteConfigs();
resetUI();
emit showLoginPage("Sync error. Please try again.");
return; 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(); client_->initialSync();
initialSyncTimer_->start(INITIAL_SYNC_RETRY_TIMEOUT); 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 void

View File

@ -401,7 +401,7 @@ MatrixClient::initialSync() noexcept
if (status == 0 || status >= 400) { if (status == 0 || status >= 400) {
qDebug() << "Error code received" << status; qDebug() << "Error code received" << status;
emit initialSyncFailed(); emit initialSyncFailed(status);
return; return;
} }