From 39f74a7293577eb40d40d1f03bd1c1de328b4e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Thu, 9 Oct 2025 07:48:46 +0200 Subject: [PATCH] feat: Make display sending event configurable in Room.sendEvent() It might be desirable to not display a pending event in the timeline. For example when sending a message from a push notification while the app is in background, the app does not sync at all so the pending events will be misplaced. --- lib/src/room.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 42c1ca08..861db5da 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1119,6 +1119,12 @@ class Room { String? editEventId, String? threadRootEventId, String? threadLastEventId, + + /// Displays an event in the timeline with the transaction ID as the event + /// ID and a status of SENDING, SENT or ERROR until it gets replaced by + /// the sync event. Using this can display a different sort order of events + /// as the sync event does replace but not relocate the pending event. + bool displayPendingEvent = true, }) async { // Create new transaction id final String messageID; @@ -1223,7 +1229,7 @@ class Room { // we need to add the transaction ID to the set of events that are currently queued to be sent // even before the fake sync is called, so that the event constructor can check if the event is in the sending state sendingQueueEventsByTxId.add(messageID); - await _handleFakeSync(syncUpdate); + if (displayPendingEvent) await _handleFakeSync(syncUpdate); final completer = Completer(); sendingQueue.add(completer); while (sendingQueue.first != completer) { @@ -1257,7 +1263,7 @@ class Room { Logs().w('Problem while sending message', e, s); syncUpdate.rooms!.join!.values.first.timeline!.events!.first .unsigned![messageSendingStatusKey] = EventStatus.error.intValue; - await _handleFakeSync(syncUpdate); + if (displayPendingEvent) await _handleFakeSync(syncUpdate); completer.complete(); sendingQueue.remove(completer); sendingQueueEventsByTxId.remove(messageID); @@ -1276,7 +1282,7 @@ class Room { syncUpdate.rooms!.join!.values.first.timeline!.events!.first .unsigned![messageSendingStatusKey] = EventStatus.sent.intValue; syncUpdate.rooms!.join!.values.first.timeline!.events!.first.eventId = res; - await _handleFakeSync(syncUpdate); + if (displayPendingEvent) await _handleFakeSync(syncUpdate); completer.complete(); sendingQueue.remove(completer); sendingQueueEventsByTxId.remove(messageID);