Add hooks

This commit is contained in:
Will Hunt 2021-09-24 14:04:06 +01:00
parent 9c4d018e4e
commit ba449705d1
4 changed files with 59 additions and 0 deletions

View file

@ -1371,6 +1371,17 @@ class AuthHandler(BaseHandler):
access_token=access_token,
)
# Inform interested appservices
self.hs.get_application_service_handler().notify_synthetic_event(
"m.user.logout",
user_id,
{
"user_id": user_info.user_id,
"device_id": user_info.device_id,
}
)
# delete pushers associated with this access token
if user_info.token_id is not None:
await self.hs.get_pusherpool().remove_pushers_by_access_token(
@ -1408,6 +1419,16 @@ class AuthHandler(BaseHandler):
user_id, (token_id for _, token_id, _ in tokens_and_devices)
)
# Inform interested appservices
self.hs.get_application_service_handler().notify_synthetic_event(
"m.user.logout",
user_id,
{
"user_id": user_id,
"device_id": device_id,
}
)
async def add_threepid(
self, user_id: str, medium: str, address: str, validated_at: int
) -> None:

View file

@ -38,6 +38,7 @@ class DeactivateAccountHandler(BaseHandler):
self._room_member_handler = hs.get_room_member_handler()
self._identity_handler = hs.get_identity_handler()
self._profile_handler = hs.get_profile_handler()
self._application_service_handler = hs.get_application_service_handler()
self.user_directory_handler = hs.get_user_directory_handler()
self._server_name = hs.hostname
@ -159,6 +160,16 @@ class DeactivateAccountHandler(BaseHandler):
# Mark the user as deactivated.
await self.store.set_user_deactivated_status(user_id, True)
# Inform interested appservices
self._application_service_handler.notify_synthetic_event(
"m.user.deactivated",
user_id,
{
"user_id": user_id,
}
)
return identity_server_supports_unbinding
async def _reject_pending_invites_for_user(self, user_id: str) -> None:

View file

@ -30,6 +30,7 @@ class ReplicationRegisterServlet(ReplicationEndpoint):
super().__init__(hs)
self.store = hs.get_datastore()
self.registration_handler = hs.get_registration_handler()
self._application_service_handler = hs.get_application_service_handler()
@staticmethod
async def _serialize_payload(
@ -91,6 +92,20 @@ class ReplicationRegisterServlet(ReplicationEndpoint):
shadow_banned=content["shadow_banned"],
)
# Inform interested appservices
self._application_service_handler.notify_synthetic_event(
"m.user.registration",
user_id,
{
"user_id": user_id,
"guest": content["make_guest"],
"org.matrix.synapse.admin": content["admin"],
"org.matrix.synapse.user_type": content["user_type"],
"org.matrix.synapse.shadow_banned": content["shadow_banned"],
"org.matrix.synapse.appservice_id": content["appservice_id"],
}
)
return 200, {}

View file

@ -87,6 +87,7 @@ class LoginRestServlet(RestServlet):
self.auth_handler = self.hs.get_auth_handler()
self.registration_handler = hs.get_registration_handler()
self.appservice_handler = hs.get_application_service_handler()
self._sso_handler = hs.get_sso_handler()
self._well_known_builder = WellKnownBuilder(hs)
@ -353,6 +354,17 @@ class LoginRestServlet(RestServlet):
if callback is not None:
await callback(result)
# Inform interested appservices
self.appservice_handler.notify_synthetic_event(
"m.user.login",
user_id,
{
"user_id": user_id,
"device_id": device_id,
}
)
return result
async def _do_token_login(