From c50914498786b9a58991d3e296316493cee53c33 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Sun, 8 Nov 2020 14:54:19 +0100 Subject: [PATCH] fix: Fetching history sometimes re-sorting events in the timeline --- lib/src/database/database.dart | 2 ++ lib/src/timeline.dart | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/src/database/database.dart b/lib/src/database/database.dart index e524305b..f92ad168 100644 --- a/lib/src/database/database.dart +++ b/lib/src/database/database.dart @@ -421,6 +421,8 @@ class Database extends _$Database { if (roomUpdate.limitedTimeline) { await removeSuccessfulRoomEvents(clientId, roomUpdate.id); await updateRoomSortOrder(0.0, 0.0, clientId, roomUpdate.id); + } + if (roomUpdate.prev_batch != null) { await setRoomPrevBatch(roomUpdate.prev_batch, clientId, roomUpdate.id); } } diff --git a/lib/src/timeline.dart b/lib/src/timeline.dart index 004d49dc..462c0144 100644 --- a/lib/src/timeline.dart +++ b/lib/src/timeline.dart @@ -287,8 +287,12 @@ class Timeline { if (i < events.length) { // if the old status is larger than the new one, we also want to preserve the old status final oldStatus = events[i].status; - events[i] = - Event.fromJson(eventUpdate.content, room, eventUpdate.sortOrder); + events[i] = Event.fromJson( + eventUpdate.content, + room, + eventUpdate.type == EventUpdateType.history + ? events[i].sortOrder + : eventUpdate.sortOrder); // do we preserve the status? we should allow 0 -> -1 updates and status increases if (status < oldStatus && !(status == -1 && oldStatus == 0)) { events[i].status = oldStatus;