diff --git a/include/timeline/TimelineView.h b/include/timeline/TimelineView.h index 52bf01657d8662819a755d7df7669fa90ad9d4cc..faada44c70b919ca9c59c6ccc33714ab560ad0e7 100644 --- a/include/timeline/TimelineView.h +++ b/include/timeline/TimelineView.h @@ -27,13 +27,14 @@ #include <QStyle> #include <QStyleOption> -#include <mtx.hpp> +#include <mtx/events.hpp> +#include <mtx/responses/messages.hpp> #include "MatrixClient.h" +#include "ScrollBar.h" #include "TimelineItem.h" class FloatingButton; -class ScrollBar; struct DescInfo; // Contains info about a message shown in the history view @@ -122,6 +123,7 @@ private: void updateLastSender(const QString &user_id, TimelineDirection direction); void notifyForLastEvent(); void readLastEvent() const; + bool isScrollbarActivated() { return scroll_area_->verticalScrollBar()->value() != 0; } QString getLastEventId() const; QString getEventSender(const mtx::events::collections::TimelineEvents &event) const; diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index dd51fc52bbe95a5e35dcca97a565bd043fc1c6a2..dccc6f37cc2fa57190e106faa690816a9ffebcf6 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -21,7 +21,6 @@ #include "FloatingButton.h" #include "RoomMessages.h" -#include "ScrollBar.h" #include "timeline/TimelineView.h" #include "timeline/widgets/AudioItem.h" @@ -83,12 +82,18 @@ TimelineView::sliderRangeChanged(int min, int max) void TimelineView::fetchHistory() { - bool hasEnoughMessages = scroll_area_->verticalScrollBar()->isVisible(); + if (!isScrollbarActivated() && !isTimelineFinished) { + if (!isVisible()) { + // Check again later if the timeline became visible. + // TODO: Use a backoff strategy. + paginationTimer_->start(3000); + return; + } - if (!hasEnoughMessages && !isTimelineFinished) { isPaginationInProgress_ = true; client_->messages(room_id_, prev_batch_token_); - paginationTimer_->start(500); + paginationTimer_->start(1500); + return; }