diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-10-08 21:35:37 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2017-10-08 21:35:37 +0300 |
commit | ebe36b5713c5c85b8b85d1c15653f3f66b342823 (patch) | |
tree | e4e2850199f5ce1820f2e4950f5a1dc9f93646f4 | |
parent | Prevent FOUC (diff) | |
download | nheko-ebe36b5713c5c85b8b85d1c15653f3f66b342823.tar.xz |
Drop the loading screen if consensus can't be achieved
-rw-r--r-- | include/ChatPage.h | 9 | ||||
-rw-r--r-- | src/ChatPage.cc | 33 | ||||
-rw-r--r-- | src/MatrixClient.cc | 2 |
3 files changed, 30 insertions, 14 deletions
diff --git a/include/ChatPage.h b/include/ChatPage.h index 0a6d303b..ad1ec9e3 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -34,6 +34,10 @@ #include "TypingDisplay.h" #include "UserInfoWidget.h" +constexpr int CONSENSUS_TIMEOUT = 1000; +constexpr int SHOW_CONTENT_TIMEOUT = 3000; +constexpr int SYNC_INTERVAL = 2000; + class ChatPage : public QWidget { Q_OBJECT @@ -96,9 +100,10 @@ private: TextInputWidget *text_input_; TypingDisplay *typingDisplay_; + // Safety net if consensus is not possible or too slow. + QTimer *showContentTimer_; QTimer *consensusTimer_; - QTimer *sync_timer_; - int sync_interval_; + QTimer *syncTimer_; QString current_room_; QMap<QString, QPixmap> room_avatars_; diff --git a/src/ChatPage.cc b/src/ChatPage.cc index d3f60494..5648a830 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -33,7 +33,6 @@ namespace events = matrix::events; ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent) : QWidget(parent) - , sync_interval_(2000) , client_(client) { setStyleSheet("background-color: #fff;"); @@ -109,9 +108,9 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent) user_info_widget_ = new UserInfoWidget(sideBarTopWidget_); sideBarTopWidgetLayout_->addWidget(user_info_widget_); - sync_timer_ = new QTimer(this); - sync_timer_->setSingleShot(true); - connect(sync_timer_, SIGNAL(timeout()), this, SLOT(startSync())); + syncTimer_ = new QTimer(this); + syncTimer_->setSingleShot(true); + connect(syncTimer_, SIGNAL(timeout()), this, SLOT(startSync())); connect(user_info_widget_, SIGNAL(logout()), client_.data(), SLOT(logout())); connect(client_.data(), SIGNAL(loggedOut()), this, SLOT(logout())); @@ -213,11 +212,19 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent) this, SLOT(removeRoom(const QString &))); + showContentTimer_ = new QTimer(this); + showContentTimer_->setSingleShot(true); + connect(showContentTimer_, &QTimer::timeout, this, [=]() { + consensusTimer_->stop(); + emit contentLoaded(); + }); + consensusTimer_ = new QTimer(this); connect(consensusTimer_, &QTimer::timeout, this, [=]() { if (view_manager_->hasLoaded()) { // Remove the spinner overlay. emit contentLoaded(); + showContentTimer_->stop(); consensusTimer_->stop(); } }); @@ -228,7 +235,7 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent) void ChatPage::logout() { - sync_timer_->stop(); + syncTimer_->stop(); // Delete all config parameters. QSettings settings; @@ -307,7 +314,7 @@ ChatPage::syncFailed(const QString &msg) return; qWarning() << "Sync error:" << msg; - sync_timer_->start(sync_interval_); + syncTimer_->start(SYNC_INTERVAL); } // TODO: Should be moved in another class that manages this global list. @@ -404,7 +411,7 @@ ChatPage::syncCompleted(const SyncResponse &response) room_list_->sync(state_manager_); view_manager_->sync(response.rooms()); - sync_timer_->start(sync_interval_); + syncTimer_->start(SYNC_INTERVAL); } void @@ -457,7 +464,7 @@ ChatPage::initialSyncCompleted(const SyncResponse &response) // Initialize room list. room_list_->setInitialRooms(settingsManager_, state_manager_); - sync_timer_->start(sync_interval_); + syncTimer_->start(SYNC_INTERVAL); emit contentLoaded(); } @@ -564,9 +571,13 @@ ChatPage::loadStateFromCache() room_list_->setInitialRooms(settingsManager_, state_manager_); // Check periodically if the timelines have been loaded. - consensusTimer_->start(500); + consensusTimer_->start(CONSENSUS_TIMEOUT); + + // Show the content if consensus can't be achieved. + showContentTimer_->start(SHOW_CONTENT_TIMEOUT); - sync_timer_->start(sync_interval_); + // Start receiving events. + syncTimer_->start(SYNC_INTERVAL); } void @@ -665,5 +676,5 @@ ChatPage::updateTypingUsers(const QString &roomid, const QList<QString> &user_id ChatPage::~ChatPage() { - sync_timer_->stop(); + syncTimer_->stop(); } diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index 8c10a0a2..708e1176 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -627,7 +627,7 @@ MatrixClient::sync() noexcept QUrlQuery query; query.addQueryItem("set_presence", "online"); query.addQueryItem("filter", QJsonDocument(filter).toJson(QJsonDocument::Compact)); - query.addQueryItem("timeout", "30000"); + query.addQueryItem("timeout", "15000"); query.addQueryItem("access_token", token_); if (next_batch_.isEmpty()) { |