Show a better message on the login screen after an initial sync failure.
This commit is contained in:
parent
54582cab3a
commit
b60554b8fd
@ -127,6 +127,8 @@ private:
|
||||
template<class Collection>
|
||||
void updateUserMetadata(const std::vector<Collection> &collection);
|
||||
|
||||
void retryInitialSync();
|
||||
|
||||
QHBoxLayout *topLayout_;
|
||||
Splitter *splitter;
|
||||
|
||||
@ -156,6 +158,7 @@ private:
|
||||
QTimer *showContentTimer_;
|
||||
QTimer *consensusTimer_;
|
||||
QTimer *syncTimeoutTimer_;
|
||||
QTimer *initialSyncTimer_;
|
||||
|
||||
QString current_room_;
|
||||
QString current_community_;
|
||||
@ -191,7 +194,7 @@ private:
|
||||
|
||||
// If the number of failures exceeds a certain threshold we
|
||||
// return to the login page.
|
||||
int initialSyncFailures = 0;
|
||||
int initialSyncFailures_ = 0;
|
||||
};
|
||||
|
||||
template<class Collection>
|
||||
|
@ -129,7 +129,7 @@ signals:
|
||||
void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name);
|
||||
void getOwnCommunitiesResponse(const QList<QString> &own_communities);
|
||||
void initialSyncCompleted(const mtx::responses::Sync &response);
|
||||
void initialSyncFailed(const QString &msg);
|
||||
void initialSyncFailed();
|
||||
void syncCompleted(const mtx::responses::Sync &response);
|
||||
void syncFailed(const QString &msg);
|
||||
void joinFailed(const QString &msg);
|
||||
|
@ -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() {}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user