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:
parent
b1b3f36fee
commit
39f74a7293
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue