summary refs log tree commit diff
diff options
context:
space:
mode:
authorWill Hunt <will@half-shot.uk>2021-09-24 14:04:06 +0100
committerWill Hunt <will@half-shot.uk>2021-09-24 14:04:06 +0100
commitba449705d1ffcc7acb439267af5c5356d79ffee1 (patch)
treeea123543b40b097685a2d3af9fdb8b3c81ececc2
parentSetup synthetic_events structure (diff)
downloadsynapse-hs/as-synthetic-events.tar.xz
-rw-r--r--synapse/handlers/auth.py21
-rw-r--r--synapse/handlers/deactivate_account.py11
-rw-r--r--synapse/replication/http/register.py15
-rw-r--r--synapse/rest/client/login.py12
4 files changed, 59 insertions, 0 deletions
diff --git a/synapse/handlers/auth.py b/synapse/handlers/auth.py
index 0f80dfdc43..231829aff8 100644
--- a/synapse/handlers/auth.py
+++ b/synapse/handlers/auth.py
@@ -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:
diff --git a/synapse/handlers/deactivate_account.py b/synapse/handlers/deactivate_account.py
index 9ae5b7750e..5324d9573c 100644
--- a/synapse/handlers/deactivate_account.py
+++ b/synapse/handlers/deactivate_account.py
@@ -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:
diff --git a/synapse/replication/http/register.py b/synapse/replication/http/register.py
index d6dd7242eb..57aefa8692 100644
--- a/synapse/replication/http/register.py
+++ b/synapse/replication/http/register.py
@@ -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, {}
 
 
diff --git a/synapse/rest/client/login.py b/synapse/rest/client/login.py
index 64446fc486..1fbabc0dee 100644
--- a/synapse/rest/client/login.py
+++ b/synapse/rest/client/login.py
@@ -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(