diff --git a/lib/src/room.dart b/lib/src/room.dart index 54f389b..fd9999c 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -719,7 +719,7 @@ class Room { 'transaction_id': messageID, }, ])))); - await client.handleSync(syncUpdate); + await _handleFakeSync(syncUpdate); // Send the text and on success, store and display a *sent* event. try { @@ -731,14 +731,15 @@ class Room { syncUpdate.rooms.join.values.first.timeline.events.first .unsigned[MessageSendingStatusKey] = 1; syncUpdate.rooms.join.values.first.timeline.events.first.eventId = res; - await client.handleSync(syncUpdate); + await _handleFakeSync(syncUpdate); + return res; } catch (e, s) { Logs.warning( '[Client] Problem while sending message: ' + e.toString(), s); syncUpdate.rooms.join.values.first.timeline.events.first .unsigned[MessageSendingStatusKey] = -1; - await client.handleSync(syncUpdate); + await _handleFakeSync(syncUpdate); } return null; } @@ -1588,4 +1589,15 @@ class Room { } await client.encryption.keyManager.request(this, sessionId, senderKey); } + + Future _handleFakeSync(SyncUpdate syncUpdate, + {bool sortAtTheEnd = false}) async { + if (client.database != null) { + await client.database.transaction(() async { + await client.handleSync(syncUpdate, sortAtTheEnd: sortAtTheEnd); + }); + } else { + await client.handleSync(syncUpdate, sortAtTheEnd: sortAtTheEnd); + } + } }