From 448b211edf5c4479a3c12d685a65b319481988a5 Mon Sep 17 00:00:00 2001 From: buidanhnam Date: Mon, 6 Apr 2026 11:16:53 +0700 Subject: [PATCH] skipQueue Use for batch sends where /// multiple events should be sent concurrently instead of one at a time --- lib/src/room.dart | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 0875e0260..f5ed51924 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -861,6 +861,9 @@ class Room { /// 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, + /// If true, skips the sequential sending queue. Use for batch sends where + /// multiple events should be sent concurrently instead of one at a time. + bool skipQueue = false, }) async { txid ??= client.generateUniqueTransactionId(); await client.database.storeFile( @@ -1071,6 +1074,7 @@ class Room { threadRootEventId: threadRootEventId, threadLastEventId: threadLastEventId, displayPendingEvent: displayPendingEvent, + skipQueue: skipQueue, ); await client.database.deleteFile( Uri(scheme: 'cache', host: 'file', path: txid), @@ -1167,6 +1171,9 @@ class Room { /// 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, + /// If true, skips the sequential sending queue. Use for batch sends where + /// multiple events should be sent concurrently instead of one at a time. + bool skipQueue = false, }) async { // Create new transaction id final String messageID; @@ -1272,10 +1279,13 @@ class Room { // 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); if (displayPendingEvent) await _handleFakeSync(syncUpdate); - final completer = Completer(); - sendingQueue.add(completer); - while (sendingQueue.first != completer) { - await sendingQueue.first.future; + Completer? completer; + if (!skipQueue) { + completer = Completer(); + sendingQueue.add(completer); + while (sendingQueue.first != completer) { + await sendingQueue.first.future; + } } final timeoutDate = DateTime.now().add(client.sendTimelineEventTimeout); @@ -1306,8 +1316,8 @@ class Room { syncUpdate.rooms!.join!.values.first.timeline!.events!.first .unsigned![messageSendingStatusKey] = EventStatus.error.intValue; if (displayPendingEvent) await _handleFakeSync(syncUpdate); - completer.complete(); - sendingQueue.remove(completer); + completer?.complete(); + if (completer != null) sendingQueue.remove(completer); sendingQueueEventsByTxId.remove(messageID); if (e is EventTooLarge || (e is MatrixException && e.error == MatrixError.M_FORBIDDEN)) { @@ -1325,7 +1335,8 @@ class Room { .unsigned![messageSendingStatusKey] = EventStatus.sent.intValue; syncUpdate.rooms!.join!.values.first.timeline!.events!.first.eventId = res; if (displayPendingEvent) await _handleFakeSync(syncUpdate); - completer.complete(); + completer?.complete(); + if (completer != null) sendingQueue.remove(completer); sendingQueue.remove(completer); sendingQueueEventsByTxId.remove(messageID); return res;