summary refs log tree commit diff
diff options
context:
space:
mode:
authorLasath Fernando <devel@lasath.org>2020-04-28 02:07:24 -0700
committerLasath Fernando <devel@lasath.org>2020-04-29 13:52:39 -0700
commit1f9d3024b1893da0ff438ff4ac9e9425e3561c7d (patch)
tree3bad2ac72d8fde85307c7debeec4641dc6700980
parentMerge pull request #183 from shocklateboy92/features/smooth-scroll (diff)
downloadnheko-1f9d3024b1893da0ff438ff4ac9e9425e3561c7d.tar.xz
Add visual indication that data is being fetched
This turns `paginationInProgress` field of `TimelineModel` into a `Q_PROPERTY`, so the Ui can bind to it.
For the moment, I'm showing the same spinner as we do during initial sync. It's not ideal, on the count of being giant and in the middle but it's better than nothing. We can make it more subtle later.
-rw-r--r--resources/qml/TimelineView.qml2
-rw-r--r--src/timeline/TimelineModel.cpp20
-rw-r--r--src/timeline/TimelineModel.h7
3 files changed, 23 insertions, 6 deletions
diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml

index c42cd6e9..3651a6f1 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml
@@ -93,7 +93,7 @@ Page { BusyIndicator { anchors.centerIn: parent - running: timelineManager.isInitialSync + running: timelineManager.isInitialSync || chat.model.paginationInProgress height: 200 width: 200 z: 3 diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index e3a1a781..af5bdc82 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -433,14 +433,25 @@ TimelineModel::canFetchMore(const QModelIndex &) const } 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(); @@ -455,12 +466,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..14276a5a 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h
@@ -124,6 +124,7 @@ class TimelineModel : public QAbstractListModel Q_PROPERTY(std::vector<QString> 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 +209,7 @@ public slots: } } std::vector<QString> typingUsers() const { return typingUsers_; } + bool paginationInProgress() const { return m_paginationInProgress; } QString reply() const { return reply_; } void setReply(QString newReply) @@ -246,6 +248,7 @@ signals: void eventFetched(QString requestingEvent, mtx::events::collections::TimelineEvents event); void typingUsersChanged(std::vector<QString> users); void replyChanged(QString reply); + void paginationInProgressChanged(const bool); private: DecryptionResult decryptEvent( @@ -261,6 +264,8 @@ private: mtx::http::RequestErr err); void readEvent(const std::string &id); + void setPaginationInProgress(const bool paginationInProgress); + QHash<QString, mtx::events::collections::TimelineEvents> events; QSet<QString> read; QList<QString> pending; @@ -270,8 +275,8 @@ private: QString prev_batch_token_; bool isInitialSync = true; - bool paginationInProgress = false; bool decryptDescription = true; + bool m_paginationInProgress = false; QString currentId; QString reply_;