diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index d1a76f83..78435713 100644
--- a/src/ChatPage.cc
+++ b/src/ChatPage.cc
@@ -42,8 +42,9 @@
#include "dialogs/ReadReceipts.h"
#include "timeline/TimelineViewManager.h"
-constexpr int MAX_INITIAL_SYNC_FAILURES = 5;
-constexpr int SYNC_RETRY_TIMEOUT = 40000;
+constexpr int MAX_INITIAL_SYNC_FAILURES = 7;
+constexpr int SYNC_RETRY_TIMEOUT = 40 * 1000;
+constexpr int INITIAL_SYNC_RETRY_TIMEOUT = 240 * 1000;
ChatPage *ChatPage::instance_ = nullptr;
@@ -295,29 +296,8 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
&MatrixClient::initialSyncCompleted,
this,
&ChatPage::initialSyncCompleted);
- connect(client_.data(), &MatrixClient::initialSyncFailed, this, [=](const QString &msg) {
- if (client_->getHomeServer().isEmpty()) {
- deleteConfigs();
- return;
- }
-
- initialSyncFailures += 1;
-
- if (initialSyncFailures >= MAX_INITIAL_SYNC_FAILURES) {
- initialSyncFailures = 0;
-
- deleteConfigs();
-
- emit showLoginPage(msg);
- emit contentLoaded();
- return;
- }
-
- qWarning() << msg;
- qWarning() << "Retrying initial sync";
-
- client_->initialSync();
- });
+ connect(
+ client_.data(), &MatrixClient::initialSyncFailed, this, &ChatPage::retryInitialSync);
connect(client_.data(), &MatrixClient::syncCompleted, this, &ChatPage::syncCompleted);
connect(client_.data(),
&MatrixClient::getOwnProfileResponse,
@@ -378,6 +358,9 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
}
});
+ initialSyncTimer_ = new QTimer(this);
+ connect(initialSyncTimer_, &QTimer::timeout, this, &ChatPage::retryInitialSync);
+
syncTimeoutTimer_ = new QTimer(this);
connect(syncTimeoutTimer_, &QTimer::timeout, this, [=]() {
if (client_->getHomeServer().isEmpty()) {
@@ -489,6 +472,8 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
}
client_->initialSync();
+
+ initialSyncTimer_->start(INITIAL_SYNC_RETRY_TIMEOUT);
}
void
@@ -519,6 +504,8 @@ ChatPage::syncCompleted(const mtx::responses::Sync &response)
void
ChatPage::initialSyncCompleted(const mtx::responses::Sync &response)
{
+ initialSyncTimer_->stop();
+
auto joined = response.rooms.join;
for (auto it = joined.cbegin(); it != joined.cend(); ++it) {
@@ -975,4 +962,33 @@ ChatPage::setGroupViewState(bool isEnabled)
communitiesSideBar_->show();
}
+void
+ChatPage::retryInitialSync()
+{
+ initialSyncTimer_->stop();
+
+ if (client_->getHomeServer().isEmpty()) {
+ deleteConfigs();
+ return;
+ }
+
+ initialSyncFailures_ += 1;
+
+ if (initialSyncFailures_ >= MAX_INITIAL_SYNC_FAILURES) {
+ initialSyncFailures_ = 0;
+
+ deleteConfigs();
+
+ emit showLoginPage(
+ tr("The client couldn't sync with the server. Please try again."));
+ emit contentLoaded();
+ return;
+ }
+
+ qWarning() << "Retrying initial sync";
+
+ client_->initialSync();
+ initialSyncTimer_->start(INITIAL_SYNC_RETRY_TIMEOUT);
+}
+
ChatPage::~ChatPage() {}
diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc
index 69888719..b51c14c8 100644
--- a/src/MatrixClient.cc
+++ b/src/MatrixClient.cc
@@ -270,7 +270,7 @@ MatrixClient::sync() noexcept
mtx::responses::Sync response = nlohmann::json::parse(data);
emit syncCompleted(response);
} catch (std::exception &e) {
- qWarning() << "Sync malformed response: " << e.what();
+ qWarning() << "Sync error: " << e.what();
}
});
}
@@ -384,7 +384,8 @@ MatrixClient::initialSync() noexcept
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (status == 0 || status >= 400) {
- emit initialSyncFailed(reply->errorString());
+ qDebug() << "Error code received" << status;
+ emit initialSyncFailed();
return;
}
@@ -394,7 +395,8 @@ MatrixClient::initialSync() noexcept
mtx::responses::Sync response = nlohmann::json::parse(data);
emit initialSyncCompleted(response);
} catch (std::exception &e) {
- qWarning() << "Sync malformed response" << e.what();
+ qWarning() << "Initial sync error:" << e.what();
+ emit initialSyncFailed();
return;
}
|