Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions lib/src/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down