Merge pull request #1866 from famedly/krille/store-last-event-in-database-after-decryption
fix: Correctly store lastEvent in database after decryption
This commit is contained in:
commit
faae7935b5
|
|
@ -193,9 +193,17 @@ class KeyManager {
|
||||||
event.content['session_id'] == sessionId) {
|
event.content['session_id'] == sessionId) {
|
||||||
final decrypted = encryption.decryptRoomEventSync(roomId, event);
|
final decrypted = encryption.decryptRoomEventSync(roomId, event);
|
||||||
if (decrypted.type != EventTypes.Encrypted) {
|
if (decrypted.type != EventTypes.Encrypted) {
|
||||||
// No need to persist it as the lastEvent is persisted in the sync
|
// Update the last event in memory first
|
||||||
// right after processing to-device messages:
|
|
||||||
room.lastEvent = decrypted;
|
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
|
// and finally broadcast the new session
|
||||||
|
|
|
||||||
|
|
@ -318,6 +318,9 @@ void main() {
|
||||||
final roomId = '!someroom:example.org';
|
final roomId = '!someroom:example.org';
|
||||||
final sessionId = inbound.session_id();
|
final sessionId = inbound.session_id();
|
||||||
final room = Room(id: roomId, client: client);
|
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);
|
client.rooms.add(room);
|
||||||
// we build up an encrypted message so that we can test if it successfully decrypted afterwards
|
// we build up an encrypted message so that we can test if it successfully decrypted afterwards
|
||||||
room.setState(
|
room.setState(
|
||||||
|
|
@ -475,6 +478,11 @@ void main() {
|
||||||
expect(room.lastEvent?.type, 'm.room.message');
|
expect(room.lastEvent?.type, 'm.room.message');
|
||||||
expect(room.lastEvent?.content['body'], 'foxies');
|
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();
|
inbound.free();
|
||||||
session.free();
|
session.free();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue