diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index d471f9a5..e3003a37 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -193,9 +193,17 @@ class KeyManager { event.content['session_id'] == sessionId) { final decrypted = encryption.decryptRoomEventSync(roomId, event); if (decrypted.type != EventTypes.Encrypted) { - // No need to persist it as the lastEvent is persisted in the sync - // right after processing to-device messages: + // Update the last event in memory first room.lastEvent = decrypted; + + // To persist it in database and trigger UI updates: + await client.database?.transaction(() async { + await client.handleSync( + SyncUpdate( + nextBatch: '', + rooms: RoomsUpdate(join: {room.id: JoinedRoomUpdate()})), + ); + }); } } // and finally broadcast the new session diff --git a/test/encryption/key_manager_test.dart b/test/encryption/key_manager_test.dart index 0270dfa3..48d343a4 100644 --- a/test/encryption/key_manager_test.dart +++ b/test/encryption/key_manager_test.dart @@ -318,6 +318,9 @@ void main() { final roomId = '!someroom:example.org'; final sessionId = inbound.session_id(); final room = Room(id: roomId, client: client); + final nextSyncUpdateFuture = client.onSync.stream + .firstWhere((update) => update.rooms != null) + .timeout(const Duration(seconds: 5)); client.rooms.add(room); // we build up an encrypted message so that we can test if it successfully decrypted afterwards room.setState( @@ -475,6 +478,11 @@ void main() { expect(room.lastEvent?.type, 'm.room.message'); expect(room.lastEvent?.content['body'], 'foxies'); + // test if a fake sync has been performed to update the GUI and store the + // decrypted last event + final syncUpdate = await nextSyncUpdateFuture; + expect(syncUpdate.rooms?.join?.containsKey(room.id), true); + inbound.free(); session.free(); });