Skip to content

Commit

Permalink
Check cache before invalidating group sessions on member event
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Mar 13, 2023
1 parent 41b288a commit 72fb0f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions mautrix/client/state_store/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ async def update_state(self, evt: StateEvent) -> None:
if evt.type == EventType.ROOM_POWER_LEVELS:
await self.set_power_levels(evt.room_id, evt.content)
elif evt.type == EventType.ROOM_MEMBER:
evt.unsigned["mautrix_prev_membership"] = await self.get_member(
evt.room_id, UserID(evt.state_key)
)
await self.set_member(evt.room_id, UserID(evt.state_key), evt.content)
elif evt.type == EventType.ROOM_ENCRYPTION:
await self.set_encryption_info(evt.room_id, evt.content)
Expand Down
13 changes: 11 additions & 2 deletions mautrix/crypto/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
DeviceOTKCount,
EncryptionAlgorithm,
EventType,
Member,
Membership,
StateEvent,
ToDeviceEvent,
Expand Down Expand Up @@ -172,10 +173,18 @@ async def handle_member_event(self, evt: StateEvent) -> None:
if prev == cur or ignored_changes.get(prev) == cur:
return
src = getattr(evt, "source", None)
prev_cache = evt.unsigned.get("mautrix_prev_membership")
if isinstance(prev_cache, Member) and prev_cache.membership == cur:
self.log.debug(
f"Got duplicate membership state event in {evt.room_id} changing {evt.state_key} "
f"from {prev} to {cur}, cached state was {prev_cache} (event ID: {evt.event_id}, "
f"sync source: {src})"
)
return
self.log.debug(
f"Got membership state event in {evt.room_id} changing {evt.state_key} from "
f"{prev} to {cur} (event ID: {evt.event_id}, sync source: {src}), "
"invalidating group session"
f"{prev} to {cur} (event ID: {evt.event_id}, sync source: {src}, "
f"cached: {prev_cache.membership}), invalidating group session"
)
await self.crypto_store.remove_outbound_group_session(evt.room_id)

Expand Down

0 comments on commit 72fb0f6

Please sign in to comment.