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.
This commit is contained in:
Christian Kußowski 2025-10-09 07:48:46 +02:00
parent b1b3f36fee
commit 39f74a7293
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652
1 changed files with 9 additions and 3 deletions

View File

@ -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);