mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Drop the loading screen if consensus can't be achieved
This commit is contained in:
parent
6e1285bb0e
commit
ebe36b5713
3 changed files with 30 additions and 14 deletions
|
@ -34,6 +34,10 @@
|
||||||
#include "TypingDisplay.h"
|
#include "TypingDisplay.h"
|
||||||
#include "UserInfoWidget.h"
|
#include "UserInfoWidget.h"
|
||||||
|
|
||||||
|
constexpr int CONSENSUS_TIMEOUT = 1000;
|
||||||
|
constexpr int SHOW_CONTENT_TIMEOUT = 3000;
|
||||||
|
constexpr int SYNC_INTERVAL = 2000;
|
||||||
|
|
||||||
class ChatPage : public QWidget
|
class ChatPage : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -96,9 +100,10 @@ private:
|
||||||
TextInputWidget *text_input_;
|
TextInputWidget *text_input_;
|
||||||
TypingDisplay *typingDisplay_;
|
TypingDisplay *typingDisplay_;
|
||||||
|
|
||||||
|
// Safety net if consensus is not possible or too slow.
|
||||||
|
QTimer *showContentTimer_;
|
||||||
QTimer *consensusTimer_;
|
QTimer *consensusTimer_;
|
||||||
QTimer *sync_timer_;
|
QTimer *syncTimer_;
|
||||||
int sync_interval_;
|
|
||||||
|
|
||||||
QString current_room_;
|
QString current_room_;
|
||||||
QMap<QString, QPixmap> room_avatars_;
|
QMap<QString, QPixmap> room_avatars_;
|
||||||
|
|
|
@ -33,7 +33,6 @@ namespace events = matrix::events;
|
||||||
|
|
||||||
ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, sync_interval_(2000)
|
|
||||||
, client_(client)
|
, client_(client)
|
||||||
{
|
{
|
||||||
setStyleSheet("background-color: #fff;");
|
setStyleSheet("background-color: #fff;");
|
||||||
|
@ -109,9 +108,9 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
user_info_widget_ = new UserInfoWidget(sideBarTopWidget_);
|
user_info_widget_ = new UserInfoWidget(sideBarTopWidget_);
|
||||||
sideBarTopWidgetLayout_->addWidget(user_info_widget_);
|
sideBarTopWidgetLayout_->addWidget(user_info_widget_);
|
||||||
|
|
||||||
sync_timer_ = new QTimer(this);
|
syncTimer_ = new QTimer(this);
|
||||||
sync_timer_->setSingleShot(true);
|
syncTimer_->setSingleShot(true);
|
||||||
connect(sync_timer_, SIGNAL(timeout()), this, SLOT(startSync()));
|
connect(syncTimer_, SIGNAL(timeout()), this, SLOT(startSync()));
|
||||||
|
|
||||||
connect(user_info_widget_, SIGNAL(logout()), client_.data(), SLOT(logout()));
|
connect(user_info_widget_, SIGNAL(logout()), client_.data(), SLOT(logout()));
|
||||||
connect(client_.data(), SIGNAL(loggedOut()), this, SLOT(logout()));
|
connect(client_.data(), SIGNAL(loggedOut()), this, SLOT(logout()));
|
||||||
|
@ -213,11 +212,19 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
this,
|
this,
|
||||||
SLOT(removeRoom(const QString &)));
|
SLOT(removeRoom(const QString &)));
|
||||||
|
|
||||||
|
showContentTimer_ = new QTimer(this);
|
||||||
|
showContentTimer_->setSingleShot(true);
|
||||||
|
connect(showContentTimer_, &QTimer::timeout, this, [=]() {
|
||||||
|
consensusTimer_->stop();
|
||||||
|
emit contentLoaded();
|
||||||
|
});
|
||||||
|
|
||||||
consensusTimer_ = new QTimer(this);
|
consensusTimer_ = new QTimer(this);
|
||||||
connect(consensusTimer_, &QTimer::timeout, this, [=]() {
|
connect(consensusTimer_, &QTimer::timeout, this, [=]() {
|
||||||
if (view_manager_->hasLoaded()) {
|
if (view_manager_->hasLoaded()) {
|
||||||
// Remove the spinner overlay.
|
// Remove the spinner overlay.
|
||||||
emit contentLoaded();
|
emit contentLoaded();
|
||||||
|
showContentTimer_->stop();
|
||||||
consensusTimer_->stop();
|
consensusTimer_->stop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -228,7 +235,7 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
void
|
void
|
||||||
ChatPage::logout()
|
ChatPage::logout()
|
||||||
{
|
{
|
||||||
sync_timer_->stop();
|
syncTimer_->stop();
|
||||||
|
|
||||||
// Delete all config parameters.
|
// Delete all config parameters.
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
@ -307,7 +314,7 @@ ChatPage::syncFailed(const QString &msg)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qWarning() << "Sync error:" << msg;
|
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.
|
// 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_);
|
room_list_->sync(state_manager_);
|
||||||
view_manager_->sync(response.rooms());
|
view_manager_->sync(response.rooms());
|
||||||
|
|
||||||
sync_timer_->start(sync_interval_);
|
syncTimer_->start(SYNC_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -457,7 +464,7 @@ ChatPage::initialSyncCompleted(const SyncResponse &response)
|
||||||
// Initialize room list.
|
// Initialize room list.
|
||||||
room_list_->setInitialRooms(settingsManager_, state_manager_);
|
room_list_->setInitialRooms(settingsManager_, state_manager_);
|
||||||
|
|
||||||
sync_timer_->start(sync_interval_);
|
syncTimer_->start(SYNC_INTERVAL);
|
||||||
|
|
||||||
emit contentLoaded();
|
emit contentLoaded();
|
||||||
}
|
}
|
||||||
|
@ -564,9 +571,13 @@ ChatPage::loadStateFromCache()
|
||||||
room_list_->setInitialRooms(settingsManager_, state_manager_);
|
room_list_->setInitialRooms(settingsManager_, state_manager_);
|
||||||
|
|
||||||
// Check periodically if the timelines have been loaded.
|
// Check periodically if the timelines have been loaded.
|
||||||
consensusTimer_->start(500);
|
consensusTimer_->start(CONSENSUS_TIMEOUT);
|
||||||
|
|
||||||
sync_timer_->start(sync_interval_);
|
// Show the content if consensus can't be achieved.
|
||||||
|
showContentTimer_->start(SHOW_CONTENT_TIMEOUT);
|
||||||
|
|
||||||
|
// Start receiving events.
|
||||||
|
syncTimer_->start(SYNC_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -665,5 +676,5 @@ ChatPage::updateTypingUsers(const QString &roomid, const QList<QString> &user_id
|
||||||
|
|
||||||
ChatPage::~ChatPage()
|
ChatPage::~ChatPage()
|
||||||
{
|
{
|
||||||
sync_timer_->stop();
|
syncTimer_->stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -627,7 +627,7 @@ MatrixClient::sync() noexcept
|
||||||
QUrlQuery query;
|
QUrlQuery query;
|
||||||
query.addQueryItem("set_presence", "online");
|
query.addQueryItem("set_presence", "online");
|
||||||
query.addQueryItem("filter", QJsonDocument(filter).toJson(QJsonDocument::Compact));
|
query.addQueryItem("filter", QJsonDocument(filter).toJson(QJsonDocument::Compact));
|
||||||
query.addQueryItem("timeout", "30000");
|
query.addQueryItem("timeout", "15000");
|
||||||
query.addQueryItem("access_token", token_);
|
query.addQueryItem("access_token", token_);
|
||||||
|
|
||||||
if (next_batch_.isEmpty()) {
|
if (next_batch_.isEmpty()) {
|
||||||
|
|
Loading…
Reference in a new issue