Merge pull request #2162 from famedly/krille/display-sending-event-configurable

feat: Make display sending event configurable in Room.sendEvent()
This commit is contained in:
Krille-chan 2025-10-09 07:56:08 +02:00 committed by GitHub
commit b8bd1b3cc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 3 deletions

View File

@ -1119,6 +1119,12 @@ class Room {
String? editEventId, String? editEventId,
String? threadRootEventId, String? threadRootEventId,
String? threadLastEventId, 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 { }) async {
// Create new transaction id // Create new transaction id
final String messageID; 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 // 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 // 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); sendingQueueEventsByTxId.add(messageID);
await _handleFakeSync(syncUpdate); if (displayPendingEvent) await _handleFakeSync(syncUpdate);
final completer = Completer(); final completer = Completer();
sendingQueue.add(completer); sendingQueue.add(completer);
while (sendingQueue.first != completer) { while (sendingQueue.first != completer) {
@ -1257,7 +1263,7 @@ class Room {
Logs().w('Problem while sending message', e, s); Logs().w('Problem while sending message', e, s);
syncUpdate.rooms!.join!.values.first.timeline!.events!.first syncUpdate.rooms!.join!.values.first.timeline!.events!.first
.unsigned![messageSendingStatusKey] = EventStatus.error.intValue; .unsigned![messageSendingStatusKey] = EventStatus.error.intValue;
await _handleFakeSync(syncUpdate); if (displayPendingEvent) await _handleFakeSync(syncUpdate);
completer.complete(); completer.complete();
sendingQueue.remove(completer); sendingQueue.remove(completer);
sendingQueueEventsByTxId.remove(messageID); sendingQueueEventsByTxId.remove(messageID);
@ -1276,7 +1282,7 @@ class Room {
syncUpdate.rooms!.join!.values.first.timeline!.events!.first syncUpdate.rooms!.join!.values.first.timeline!.events!.first
.unsigned![messageSendingStatusKey] = EventStatus.sent.intValue; .unsigned![messageSendingStatusKey] = EventStatus.sent.intValue;
syncUpdate.rooms!.join!.values.first.timeline!.events!.first.eventId = res; syncUpdate.rooms!.join!.values.first.timeline!.events!.first.eventId = res;
await _handleFakeSync(syncUpdate); if (displayPendingEvent) await _handleFakeSync(syncUpdate);
completer.complete(); completer.complete();
sendingQueue.remove(completer); sendingQueue.remove(completer);
sendingQueueEventsByTxId.remove(messageID); sendingQueueEventsByTxId.remove(messageID);