fix: Correctly store lastEvent in database after decryption

This commit is contained in:
Krille 2024-06-26 14:24:45 +02:00
parent 87ee7f4cac
commit 4fd616bcbf
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652
2 changed files with 18 additions and 2 deletions

View File

@ -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

View File

@ -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();
});