diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index 7df2ed0b..997f901e 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -97,7 +97,7 @@ Page { BusyIndicator { anchors.centerIn: parent - running: timelineManager.isInitialSync + running: timelineManager.isInitialSync height: 200 width: 200 z: 3 @@ -255,6 +255,13 @@ Page { } } + footer: BusyIndicator { + anchors.horizontalCenter: parent.horizontalCenter + running: chat.model && chat.model.paginationInProgress + height: 50 + width: 50 + z: 3 + } } Rectangle { diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index d68adf92..340bae39 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -429,15 +429,26 @@ TimelineModel::canFetchMore(const QModelIndex &) const return false; } +void +TimelineModel::setPaginationInProgress(const bool paginationInProgress) +{ + if (m_paginationInProgress == paginationInProgress) { + return; + } + + m_paginationInProgress = paginationInProgress; + emit paginationInProgressChanged(m_paginationInProgress); +} + void TimelineModel::fetchMore(const QModelIndex &) { - if (paginationInProgress) { + if (m_paginationInProgress) { nhlog::ui()->warn("Already loading older messages"); return; } - paginationInProgress = true; + setPaginationInProgress(true); mtx::http::MessagesOpts opts; opts.room_id = room_id_.toStdString(); opts.from = prev_batch_token_.toStdString(); @@ -452,12 +463,13 @@ TimelineModel::fetchMore(const QModelIndex &) mtx::errors::to_string(err->matrix_error.errcode), err->matrix_error.error, err->parse_error); - paginationInProgress = false; + emit oldMessagesRetrieved(std::move(res)); + setPaginationInProgress(false); return; } emit oldMessagesRetrieved(std::move(res)); - paginationInProgress = false; + setPaginationInProgress(false); }); } diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index ae468c09..cc63eca2 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -124,6 +124,8 @@ class TimelineModel : public QAbstractListModel Q_PROPERTY(std::vector typingUsers READ typingUsers WRITE updateTypingUsers NOTIFY typingUsersChanged) Q_PROPERTY(QString reply READ reply WRITE setReply NOTIFY replyChanged RESET resetReply) + Q_PROPERTY( + bool paginationInProgress READ paginationInProgress NOTIFY paginationInProgressChanged) public: explicit TimelineModel(TimelineViewManager *manager, @@ -208,6 +210,7 @@ public slots: } } std::vector typingUsers() const { return typingUsers_; } + bool paginationInProgress() const { return m_paginationInProgress; } QString reply() const { return reply_; } void setReply(QString newReply) @@ -246,6 +249,7 @@ signals: void eventFetched(QString requestingEvent, mtx::events::collections::TimelineEvents event); void typingUsersChanged(std::vector users); void replyChanged(QString reply); + void paginationInProgressChanged(const bool); private: DecryptionResult decryptEvent( @@ -261,6 +265,8 @@ private: mtx::http::RequestErr err); void readEvent(const std::string &id); + void setPaginationInProgress(const bool paginationInProgress); + QHash events; QSet read; QList pending; @@ -269,9 +275,9 @@ private: QString room_id_; QString prev_batch_token_; - bool isInitialSync = true; - bool paginationInProgress = false; - bool decryptDescription = true; + bool isInitialSync = true; + bool decryptDescription = true; + bool m_paginationInProgress = false; QString currentId; QString reply_;