mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Retry initial sync (#19)
This commit is contained in:
parent
8a9a513ecd
commit
13e526c27d
6 changed files with 60 additions and 19 deletions
|
@ -56,6 +56,7 @@ signals:
|
||||||
void changeWindowTitle(const QString &msg);
|
void changeWindowTitle(const QString &msg);
|
||||||
void unreadMessages(int count);
|
void unreadMessages(int count);
|
||||||
void showNotification(const QString &msg);
|
void showNotification(const QString &msg);
|
||||||
|
void showLoginPage(const QString &msg);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showUnreadMessageNotification(int count);
|
void showUnreadMessageNotification(int count);
|
||||||
|
@ -74,6 +75,8 @@ private:
|
||||||
void updateTypingUsers(const QString &roomid, const QList<QString> &user_ids);
|
void updateTypingUsers(const QString &roomid, const QList<QString> &user_ids);
|
||||||
void updateDisplayNames(const RoomState &state);
|
void updateDisplayNames(const RoomState &state);
|
||||||
void loadStateFromCache();
|
void loadStateFromCache();
|
||||||
|
void deleteConfigs();
|
||||||
|
void resetUI();
|
||||||
|
|
||||||
QHBoxLayout *topLayout_;
|
QHBoxLayout *topLayout_;
|
||||||
Splitter *splitter;
|
Splitter *splitter;
|
||||||
|
@ -121,4 +124,8 @@ private:
|
||||||
|
|
||||||
// LMDB wrapper.
|
// LMDB wrapper.
|
||||||
QSharedPointer<Cache> cache_;
|
QSharedPointer<Cache> cache_;
|
||||||
|
|
||||||
|
// If the number of failures exceeds a certain threshold we
|
||||||
|
// return to the login page.
|
||||||
|
int initialSyncFailures = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,6 +43,10 @@ public:
|
||||||
signals:
|
signals:
|
||||||
void backButtonClicked();
|
void backButtonClicked();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
// Displays errors produced during the login.
|
||||||
|
void loginError(QString error_message);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
// Callback for the back button.
|
// Callback for the back button.
|
||||||
void onBackButtonClicked();
|
void onBackButtonClicked();
|
||||||
|
@ -56,9 +60,6 @@ private slots:
|
||||||
// Callback for probing the manually entered server
|
// Callback for probing the manually entered server
|
||||||
void onServerAddressEntered();
|
void onServerAddressEntered();
|
||||||
|
|
||||||
// Displays errors produced during the login.
|
|
||||||
void loginError(QString error_message);
|
|
||||||
|
|
||||||
// Callback for errors produced during server probing
|
// Callback for errors produced during server probing
|
||||||
void versionError(QString error_message);
|
void versionError(QString error_message);
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,7 @@ signals:
|
||||||
// Returned profile data for the user's account.
|
// Returned profile data for the user's account.
|
||||||
void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name);
|
void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name);
|
||||||
void initialSyncCompleted(const SyncResponse &response);
|
void initialSyncCompleted(const SyncResponse &response);
|
||||||
|
void initialSyncFailed(const QString &msg);
|
||||||
void syncCompleted(const SyncResponse &response);
|
void syncCompleted(const SyncResponse &response);
|
||||||
void syncFailed(const QString &msg);
|
void syncFailed(const QString &msg);
|
||||||
void joinFailed(const QString &msg);
|
void joinFailed(const QString &msg);
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
|
|
||||||
#include "StateEvent.h"
|
#include "StateEvent.h"
|
||||||
|
|
||||||
|
constexpr int MAX_INITIAL_SYNC_FAILURES = 5;
|
||||||
|
|
||||||
namespace events = matrix::events;
|
namespace events = matrix::events;
|
||||||
|
|
||||||
ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
|
@ -192,6 +194,24 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
SIGNAL(initialSyncCompleted(const SyncResponse &)),
|
SIGNAL(initialSyncCompleted(const SyncResponse &)),
|
||||||
this,
|
this,
|
||||||
SLOT(initialSyncCompleted(const SyncResponse &)));
|
SLOT(initialSyncCompleted(const SyncResponse &)));
|
||||||
|
connect(client_.data(), &MatrixClient::initialSyncFailed, this, [=](const QString &msg) {
|
||||||
|
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(),
|
connect(client_.data(),
|
||||||
SIGNAL(syncCompleted(const SyncResponse &)),
|
SIGNAL(syncCompleted(const SyncResponse &)),
|
||||||
this,
|
this,
|
||||||
|
@ -239,7 +259,29 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
void
|
void
|
||||||
ChatPage::logout()
|
ChatPage::logout()
|
||||||
{
|
{
|
||||||
// Delete all config parameters.
|
deleteConfigs();
|
||||||
|
|
||||||
|
resetUI();
|
||||||
|
|
||||||
|
emit close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ChatPage::resetUI()
|
||||||
|
{
|
||||||
|
room_avatars_.clear();
|
||||||
|
room_list_->clear();
|
||||||
|
settingsManager_.clear();
|
||||||
|
state_manager_.clear();
|
||||||
|
top_bar_->reset();
|
||||||
|
user_info_widget_->reset();
|
||||||
|
view_manager_->clearAll();
|
||||||
|
AvatarProvider::clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ChatPage::deleteConfigs()
|
||||||
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.beginGroup("auth");
|
settings.beginGroup("auth");
|
||||||
settings.remove("");
|
settings.remove("");
|
||||||
|
@ -253,21 +295,7 @@ ChatPage::logout()
|
||||||
|
|
||||||
cache_->deleteData();
|
cache_->deleteData();
|
||||||
|
|
||||||
// Clear the environment.
|
|
||||||
room_list_->clear();
|
|
||||||
view_manager_->clearAll();
|
|
||||||
|
|
||||||
top_bar_->reset();
|
|
||||||
user_info_widget_->reset();
|
|
||||||
client_->reset();
|
client_->reset();
|
||||||
|
|
||||||
state_manager_.clear();
|
|
||||||
settingsManager_.clear();
|
|
||||||
room_avatars_.clear();
|
|
||||||
|
|
||||||
AvatarProvider::clear();
|
|
||||||
|
|
||||||
emit close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -73,6 +73,10 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
connect(
|
connect(
|
||||||
chat_page_, SIGNAL(changeWindowTitle(QString)), this, SLOT(setWindowTitle(QString)));
|
chat_page_, SIGNAL(changeWindowTitle(QString)), this, SLOT(setWindowTitle(QString)));
|
||||||
connect(chat_page_, SIGNAL(unreadMessages(int)), trayIcon_, SLOT(setUnreadCount(int)));
|
connect(chat_page_, SIGNAL(unreadMessages(int)), trayIcon_, SLOT(setUnreadCount(int)));
|
||||||
|
connect(chat_page_, &ChatPage::showLoginPage, this, [=](const QString &msg) {
|
||||||
|
login_page_->loginError(msg);
|
||||||
|
showLoginPage();
|
||||||
|
});
|
||||||
|
|
||||||
connect(trayIcon_,
|
connect(trayIcon_,
|
||||||
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
||||||
|
|
|
@ -221,7 +221,7 @@ MatrixClient::onInitialSyncResponse(QNetworkReply *reply)
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
|
||||||
if (status == 0 || status >= 400) {
|
if (status == 0 || status >= 400) {
|
||||||
qWarning() << reply->errorString();
|
emit initialSyncFailed(reply->errorString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue