Skip to content

Commit 2ec257d

Browse files
authored
Upon deactivation, forget all of the user's rooms (#17400)
This can help ensure that the rooms are eventually purged if the other local users also forget them. Synapse already clears some of the room information as part of the `_background_remove_left_rooms` background task, but this doesn't catch `events`, `event_json`, etc.
1 parent daeaeb2 commit 2ec257d

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

changelog.d/17400.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Forget all of a user's rooms upon deactivation, enabling future purges.

synapse/handlers/deactivate_account.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ async def _part_user(self, user_id: str) -> None:
283283
ratelimit=False,
284284
require_consent=False,
285285
)
286+
287+
# Mark the room forgotten too, because they won't be able to do this
288+
# for us. This may lead to the room being purged eventually.
289+
await self._room_member_handler.forget(user, room_id)
286290
except Exception:
287291
logger.exception(
288292
"Failed to part user %r from room %r: ignoring and continuing",

tests/handlers/test_deactivate_account.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,25 @@ def test_membership_is_redacted_upon_deactivation(self) -> None:
461461
# Validate that there is no displayname in any of the events
462462
for event in events:
463463
self.assertTrue("displayname" not in event.content)
464+
465+
def test_rooms_forgotten_upon_deactivation(self) -> None:
466+
"""
467+
Tests that the user 'forgets' the rooms they left upon deactivation.
468+
"""
469+
# Create a room
470+
room_id = self.helper.create_room_as(
471+
self.user,
472+
is_public=True,
473+
tok=self.token,
474+
)
475+
476+
# Deactivate the account
477+
self._deactivate_my_account()
478+
479+
# Get all of the user's forgotten rooms
480+
forgotten_rooms = self.get_success(
481+
self._store.get_forgotten_rooms_for_user(self.user)
482+
)
483+
484+
# Validate that the created room is forgotten
485+
self.assertTrue(room_id in forgotten_rooms)

0 commit comments

Comments
 (0)