diff --git a/synapse/handlers/deactivate_account.py b/synapse/handlers/deactivate_account.py index a10b89ec30ba..a7a0d66d274d 100644 --- a/synapse/handlers/deactivate_account.py +++ b/synapse/handlers/deactivate_account.py @@ -100,10 +100,10 @@ async def deactivate_account( # unbinding identity_server_supports_unbinding = True - # Remove any threepids associated with this account locally and attempt to - # unbind them from identity server(s). - threepids = await self.store.user_get_threepids(user_id) - for threepid in threepids: + # Attempt to unbind any known bound threepids to this account from identity + # server(s). + bound_threepids = await self.store.user_get_bound_threepids(user_id) + for threepid in bound_threepids: try: result = await self._auth_handler.delete_and_unbind_threepid( user_id, threepid["medium"], threepid["address"], id_server @@ -115,6 +115,13 @@ async def deactivate_account( identity_server_supports_unbinding &= result + # Remove any local threepid associations for this account. + local_threepids = await self.store.user_get_threepids(user_id) + for threepid in local_threepids: + await self._auth_handler.delete_and_unbind_threepid( + user_id, threepid["medium"], threepid["address"], id_server + ) + # delete any devices belonging to the user, which will also # delete corresponding access tokens. await self._device_handler.delete_all_devices_for_user(user_id)