2525from synapse .api .constants import Membership
2626from synapse .api .errors import SynapseError
2727from synapse .metrics .background_process_metrics import run_as_background_process
28+ from synapse .replication .http .deactivate_account import (
29+ ReplicationNotifyAccountDeactivatedServlet ,
30+ )
2831from synapse .types import Codes , Requester , UserID , create_requester
2932
3033if TYPE_CHECKING :
@@ -45,6 +48,7 @@ def __init__(self, hs: "HomeServer"):
4548 self ._room_member_handler = hs .get_room_member_handler ()
4649 self ._identity_handler = hs .get_identity_handler ()
4750 self ._profile_handler = hs .get_profile_handler ()
51+ self ._pusher_pool = hs .get_pusherpool ()
4852 self .user_directory_handler = hs .get_user_directory_handler ()
4953 self ._server_name = hs .hostname
5054 self ._third_party_rules = hs .get_module_api_callbacks ().third_party_event_rules
@@ -53,10 +57,16 @@ def __init__(self, hs: "HomeServer"):
5357 self ._user_parter_running = False
5458 self ._third_party_rules = hs .get_module_api_callbacks ().third_party_event_rules
5559
60+ self ._notify_account_deactivated_client = None
61+
5662 # Start the user parter loop so it can resume parting users from rooms where
5763 # it left off (if it has work left to do).
58- if hs .config .worker .run_background_tasks :
64+ if hs .config .worker .worker_app is None :
5965 hs .get_reactor ().callWhenRunning (self ._start_user_parting )
66+ else :
67+ self ._notify_account_deactivated_client = (
68+ ReplicationNotifyAccountDeactivatedServlet .make_client (hs )
69+ )
6070
6171 self ._account_validity_enabled = (
6272 hs .config .account_validity .account_validity_enabled
@@ -146,7 +156,7 @@ async def deactivate_account(
146156 # Most of the pushers will have been deleted when we logged out the
147157 # associated devices above, but we still need to delete pushers not
148158 # associated with devices, e.g. email pushers.
149- await self .store .delete_all_pushers_for_user (user_id )
159+ await self ._pusher_pool .delete_all_pushers_for_user (user_id )
150160
151161 # Add the user to a table of users pending deactivation (ie.
152162 # removal from all the rooms they're a member of)
@@ -170,10 +180,6 @@ async def deactivate_account(
170180 logger .info ("Marking %s as erased" , user_id )
171181 await self .store .mark_user_erased (user_id )
172182
173- # Now start the process that goes through that list and
174- # parts users from rooms (if it isn't already running)
175- self ._start_user_parting ()
176-
177183 # Reject all pending invites and knocks for the user, so that the
178184 # user doesn't show up in the "invited" section of rooms' members list.
179185 await self ._reject_pending_invites_and_knocks_for_user (user_id )
@@ -194,15 +200,37 @@ async def deactivate_account(
194200 # Delete any server-side backup keys
195201 await self .store .bulk_delete_backup_keys_and_versions_for_user (user_id )
196202
203+ # Notify modules and start the room parting process.
204+ await self .notify_account_deactivated (user_id , by_admin = by_admin )
205+
206+ return identity_server_supports_unbinding
207+
208+ async def notify_account_deactivated (
209+ self ,
210+ user_id : str ,
211+ by_admin : bool = False ,
212+ ) -> None :
213+ """Notify modules and start the room parting process.
214+ Goes through replication if this is not the main process.
215+ """
216+ if self ._notify_account_deactivated_client is not None :
217+ await self ._notify_account_deactivated_client (
218+ user_id = user_id ,
219+ by_admin = by_admin ,
220+ )
221+ return
222+
223+ # Now start the process that goes through that list and
224+ # parts users from rooms (if it isn't already running)
225+ self ._start_user_parting ()
226+
197227 # Let modules know the user has been deactivated.
198228 await self ._third_party_rules .on_user_deactivation_status_changed (
199229 user_id ,
200230 True ,
201- by_admin ,
231+ by_admin = by_admin ,
202232 )
203233
204- return identity_server_supports_unbinding
205-
206234 async def _reject_pending_invites_and_knocks_for_user (self , user_id : str ) -> None :
207235 """Reject pending invites and knocks addressed to a given user ID.
208236
0 commit comments