refactor: Do not store room update for leave rooms not cached anyway
This adds a check before the storeRoomUpdate() call if the room is actually known. This has the effect that the call of forgetRoom() is skipped. The reason for this is an edge case in the database implementation when calling getAllKeys(). This somehow can corrupt the keys-cache and lead to some problems. I wasn't able to fix this problem yet so this refactoring is more a good-enough workaround for now to not trigger it on an initial sync. I plan to fix it with a different approach which completely removes the keys-cache in the future. However this change leads to some problems in the tests as they already rely on this edge case.
This commit is contained in:
parent
dca5177357
commit
ba38b1f97f
|
|
@ -600,16 +600,6 @@ class FakeMatrixApi extends BaseClient {
|
||||||
},
|
},
|
||||||
'timeline': {
|
'timeline': {
|
||||||
'events': [
|
'events': [
|
||||||
{
|
|
||||||
'sender': '@bob:example.com',
|
|
||||||
'type': 'm.room.member',
|
|
||||||
'state_key': '@bob:example.com',
|
|
||||||
'content': {'membership': 'join'},
|
|
||||||
'prev_content': {'membership': 'invite'},
|
|
||||||
'origin_server_ts': 1417731086795,
|
|
||||||
'event_id': '\$7365636s6r6432:example.com',
|
|
||||||
'unsigned': {'foo': 'bar'},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
'sender': '@alice:example.com',
|
'sender': '@alice:example.com',
|
||||||
'type': 'm.room.message',
|
'type': 'm.room.message',
|
||||||
|
|
|
||||||
|
|
@ -2736,6 +2736,10 @@ class Client extends MatrixApi {
|
||||||
await _handleRoomEvents(room, state, EventUpdateType.inviteState);
|
await _handleRoomEvents(room, state, EventUpdateType.inviteState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (syncRoomUpdate is LeftRoomUpdate && getRoomById(id) == null) {
|
||||||
|
Logs().d('Skip store LeftRoomUpdate for unknown room', id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
await database.storeRoomUpdate(id, syncRoomUpdate, room.lastEvent, this);
|
await database.storeRoomUpdate(id, syncRoomUpdate, room.lastEvent, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -282,16 +282,13 @@ void main() {
|
||||||
|
|
||||||
final eventUpdateList = await eventUpdateListFuture;
|
final eventUpdateList = await eventUpdateListFuture;
|
||||||
|
|
||||||
expect(eventUpdateList.length, 3);
|
expect(eventUpdateList.length, 2);
|
||||||
|
|
||||||
expect(eventUpdateList[0].type, 'm.room.member');
|
expect(eventUpdateList[0].type, 'm.room.message');
|
||||||
expect(eventUpdateList[0].roomId, '!726s6s6q:example.com');
|
expect(eventUpdateList[0].roomId, '!726s6s6q:example.com');
|
||||||
|
|
||||||
expect(eventUpdateList[1].type, 'm.room.message');
|
expect(eventUpdateList[1].type, 'm.room.message');
|
||||||
expect(eventUpdateList[1].roomId, '!726s6s6q:example.com');
|
expect(eventUpdateList[1].roomId, '!726s6s6f:example.com');
|
||||||
|
|
||||||
expect(eventUpdateList[2].type, 'm.room.message');
|
|
||||||
expect(eventUpdateList[2].roomId, '!726s6s6f:example.com');
|
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
matrix
|
matrix
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,7 @@ void main() {
|
||||||
sess = await client.encryption!.keyManager
|
sess = await client.encryption!.keyManager
|
||||||
.createOutboundGroupSession(roomId);
|
.createOutboundGroupSession(roomId);
|
||||||
final room = client.getRoomById(roomId)!;
|
final room = client.getRoomById(roomId)!;
|
||||||
|
room.partial = false;
|
||||||
final member = room.getState('m.room.member', '@alice:example.com');
|
final member = room.getState('m.room.member', '@alice:example.com');
|
||||||
member!.content['membership'] = 'leave';
|
member!.content['membership'] = 'leave';
|
||||||
room.summary.mJoinedMemberCount = room.summary.mJoinedMemberCount! - 1;
|
room.summary.mJoinedMemberCount = room.summary.mJoinedMemberCount! - 1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue