From aba47ef26bb58e0fc0f32261193991cfbee46fea Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 23 Aug 2020 17:55:31 -0400 Subject: [PATCH] Discard room members from outdated initial sync Fix in cooperation with matrix-nio commit ffc42287c22a1179a9be7d4e47555693417f715d, see its description. --- src/backend/matrix_client.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 5dc620fe..16b81a8b 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -1845,6 +1845,15 @@ class MatrixClient(nio.AsyncClient): self.models[self.user_id, "rooms"][room.room_id] = room_item if not registered or force_register_members: + model = self.models[self.user_id, room.room_id, "members"] + + # The members we initially get from lazy sync may be outdated + # and contain members that already left. + # tuple() used to avoid "dict changed size during iteration". + for member_id in tuple(model): + if member_id not in room.users: + await self.remove_member(room, member_id) + for user_id in room.users: await self.add_member(room, user_id)