From 0f43e74bcf06b2b09018d564a73aa931098eb790 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 17 Jan 2018 13:00:36 +0900 Subject: Room::getPreviousContent(): Don't skip if the last job just finished working The sequence is: RoomMessagesJob::success -> addHistoricalMessageEvents -> MessageEventModel notification -> QML notification about model reset -> MessageEventModel completes updating -> QML updates from the model but by then scrolling has already stopped at the oldest (just loaded) event -> since there's no momentum, next batch is not fetched. In order to address this, two things are done: in QML, the current position is checked in modelReset() handler; in Room (this commit), prev_batch is updated before historical messages are added (and the model gets notified, respectively), to prevent firing another job with the old prev_batch. --- room.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/room.cpp b/room.cpp index bec4cd30..8ab5b7f5 100644 --- a/room.cpp +++ b/room.cpp @@ -744,17 +744,13 @@ void Room::getPreviousContent(int limit) void Room::Private::getPreviousContent(int limit) { - if( !roomMessagesJob ) + if( !isJobRunning(roomMessagesJob) ) { roomMessagesJob = connection->callApi(id, prevBatch, limit); - connect( roomMessagesJob, &RoomMessagesJob::result, [=] { - if( !roomMessagesJob->error() ) - { - addHistoricalMessageEvents(roomMessagesJob->releaseEvents()); - prevBatch = roomMessagesJob->end(); - } - roomMessagesJob = nullptr; + connect( roomMessagesJob, &RoomMessagesJob::success, [=] { + prevBatch = roomMessagesJob->end(); + addHistoricalMessageEvents(roomMessagesJob->releaseEvents()); }); } } -- cgit v1.2.3