From 687a6341f1d9f151e848ebbaf9147574f7ed6909 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Wed, 29 Sep 2021 08:31:11 +0200 Subject: [PATCH] fix: Sent events are sorted in SENDING timeline Events with a status of 1 should be sorted in the normal timeline. They should not be stucked at the bottom. This fixes a bug where a limited timeline flag can stuck a SENT event at the bottom of the chat forever. --- lib/src/database/hive_database.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/src/database/hive_database.dart b/lib/src/database/hive_database.dart index a68e7ce1..d8c9749d 100644 --- a/lib/src/database/hive_database.dart +++ b/lib/src/database/hive_database.dart @@ -895,8 +895,9 @@ class FamedlySdkHiveDatabase extends DatabaseApi { // Update timeline fragments final key = - MultiKey(eventUpdate.roomID, status == 2 ? '' : 'SENDING').toString(); + MultiKey(eventUpdate.roomID, status >= 1 ? '' : 'SENDING').toString(); final List eventIds = (await _timelineFragmentsBox.get(key) ?? []); + if (!eventIds.contains(eventId)) { if (eventUpdate.type == EventUpdateType.history) { eventIds.add(eventId); @@ -904,10 +905,16 @@ class FamedlySdkHiveDatabase extends DatabaseApi { eventIds.insert(0, eventId); } await _timelineFragmentsBox.put(key, eventIds); + } else if (status == 2 && + prevEvent?.status == 1 && + eventUpdate.type != EventUpdateType.history) { + // Status changes from 1 -> 2? Make sure event is correctly sorted. + eventIds.remove(eventId); + eventIds.insert(0, eventId); } // If event comes from server timeline, remove sending events with this ID - if (status == 2) { + if (status >= 1) { final key = MultiKey(eventUpdate.roomID, 'SENDING').toString(); final List eventIds = (await _timelineFragmentsBox.get(key) ?? []); final i = eventIds.indexWhere((id) => id == eventId);