summary refs log tree commit diff
path: root/src/timeline/TimelineView.cpp
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-08-31 10:47:27 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-08-31 10:47:27 +0300
commit641364c105cffd24f82391a90e37531937d31c28 (patch)
tree50925fca0376e2db09b11a951015a18ff49d2dab /src/timeline/TimelineView.cpp
parentStop calling /messages if the prev_batch token is empty (diff)
downloadnheko-641364c105cffd24f82391a90e37531937d31c28.tar.xz
Handle some more edge cases in timeline
Diffstat (limited to 'src/timeline/TimelineView.cpp')
-rw-r--r--src/timeline/TimelineView.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/timeline/TimelineView.cpp b/src/timeline/TimelineView.cpp

index 6eb553e8..a77bae6a 100644 --- a/src/timeline/TimelineView.cpp +++ b/src/timeline/TimelineView.cpp
@@ -164,11 +164,19 @@ TimelineView::sliderMoved(int position) } } +bool +TimelineView::isStartOfTimeline(const mtx::responses::Messages &msgs) +{ + return (msgs.chunk.size() == 0 && (msgs.end.empty() || msgs.end == msgs.start)); +} + void TimelineView::addBackwardsEvents(const mtx::responses::Messages &msgs) { // We've reached the start of the timline and there're no more messages. - if (msgs.end.empty() || ((msgs.end == msgs.start) && msgs.chunk.size() == 0)) { + if (isStartOfTimeline(msgs)) { + nhlog::ui()->info("[{}] start of timeline reached, no more messages to fetch", + room_id_.toStdString()); isTimelineFinished = true; return; } @@ -562,6 +570,13 @@ TimelineView::init() void TimelineView::getMessages() { + if (prev_batch_token_.isEmpty()) { + nhlog::ui()->info("[{}] start of timeline reached, prev_batch token is empty", + room_id_.toStdString()); + isTimelineFinished = true; + return; + } + mtx::http::MessagesOpts opts; opts.room_id = room_id_.toStdString(); opts.from = prev_batch_token_.toStdString(); @@ -829,13 +844,22 @@ TimelineView::sendNextPendingMessage() void TimelineView::notifyForLastEvent() { - auto lastItem = scroll_layout_->itemAt(scroll_layout_->count() - 1); + if (scroll_layout_->count() == 0) { + nhlog::ui()->error("notifyForLastEvent called with empty timeline"); + return; + } + + auto lastItem = scroll_layout_->itemAt(scroll_layout_->count() - 1); + + if (!lastItem) + return; + auto *lastTimelineItem = qobject_cast<TimelineItem *>(lastItem->widget()); if (lastTimelineItem) emit updateLastTimelineMessage(room_id_, lastTimelineItem->descriptionMessage()); else - nhlog::ui()->warn("cast to TimelineView failed: {}", room_id_.toStdString()); + nhlog::ui()->warn("cast to TimelineItem failed: {}", room_id_.toStdString()); } void