diff options
author | Will Hunt <will@half-shot.uk> | 2020-10-13 11:39:30 +0100 |
---|---|---|
committer | Will Hunt <will@half-shot.uk> | 2020-10-13 11:39:30 +0100 |
commit | 3d59aa5303a7246907bbb75a9635ca08a859fc15 (patch) | |
tree | 80e9ebd250430bd92a5cfed8a10aefa501a9c074 | |
parent | Tidy up comments,docstring and fix lint (diff) | |
download | synapse-github/hs/push-reports-to-as.tar.xz |
Push event reports to appservices github/hs/push-reports-to-as hs/push-reports-to-as
-rw-r--r-- | synapse/appservice/__init__.py | 2 | ||||
-rw-r--r-- | synapse/config/appservice.py | 2 | ||||
-rw-r--r-- | synapse/handlers/appservice.py | 23 | ||||
-rw-r--r-- | synapse/rest/client/v2_alpha/report_event.py | 13 |
4 files changed, 38 insertions, 2 deletions
diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index d4a2f02fc2..6b5b66029f 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -61,6 +61,7 @@ class ApplicationService: rate_limited=True, ip_range_whitelist=None, supports_ephemeral=False, + push_reports=False, ): self.token = token self.url = ( @@ -73,6 +74,7 @@ class ApplicationService: self.id = id self.ip_range_whitelist = ip_range_whitelist self.supports_ephemeral = supports_ephemeral + self.push_reports = push_reports if "|" in self.id: raise Exception("application service ID cannot contain '|' character") diff --git a/synapse/config/appservice.py b/synapse/config/appservice.py index 746fc3cc02..b6a605a4fb 100644 --- a/synapse/config/appservice.py +++ b/synapse/config/appservice.py @@ -161,6 +161,7 @@ def _load_appservice(hostname, as_info, config_filename): ip_range_whitelist = IPSet(as_info.get("ip_range_whitelist")) supports_ephemeral = as_info.get("de.sorunome.msc2409.push_ephemeral", False) + send_reports = as_info.get("uk.half-shot.msc???.push_reports", False) return ApplicationService( token=as_info["as_token"], @@ -171,6 +172,7 @@ def _load_appservice(hostname, as_info, config_filename): sender=user_id, id=as_info["id"], supports_ephemeral=supports_ephemeral, + push_reports=send_reports, protocols=protocols, rate_limited=rate_limited, ip_range_whitelist=ip_range_whitelist, diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py index fd1e7e7ea8..c17e74bb1f 100644 --- a/synapse/handlers/appservice.py +++ b/synapse/handlers/appservice.py @@ -30,7 +30,7 @@ from synapse.metrics import ( event_processing_loop_room_count, ) from synapse.metrics.background_process_metrics import run_as_background_process -from synapse.types import Collection, RoomStreamToken, UserID +from synapse.types import Collection, RoomStreamToken, UserID, JsonDict from synapse.util.metrics import Measure logger = logging.getLogger(__name__) @@ -261,6 +261,27 @@ class ApplicationServicesHandler: ] events = events + presence_events + def on_event_report(self, room_id: str, event_id: str, user_id: str, body: JsonDict, recieved_ts: int): + services = [ + service + for service in self.store.get_app_services() + if service.supports_ephemeral and service.push_reports + ] + + if not services or not self.notify_appservices: + return + + for service in services: + event = { + "room_id": room_id, + "event_id": event_id, + "sender": user_id, + "content": body, + "ts": recieved_ts, + } + self.scheduler.submit_ephemeral_events_for_as(service, [event]) + + async def query_user_exists(self, user_id): """Check if any application service knows this user_id exists. diff --git a/synapse/rest/client/v2_alpha/report_event.py b/synapse/rest/client/v2_alpha/report_event.py index 215d619ca1..aee49ac554 100644 --- a/synapse/rest/client/v2_alpha/report_event.py +++ b/synapse/rest/client/v2_alpha/report_event.py @@ -37,8 +37,11 @@ class ReportEventRestServlet(RestServlet): self.auth = hs.get_auth() self.clock = hs.get_clock() self.store = hs.get_datastore() + self.appservice_handler = hs.get_application_service_handler() + async def on_POST(self, request, room_id, event_id): + received_ts = self.clock.time_msec() requester = await self.auth.get_user_by_req(request) user_id = requester.user.to_string() @@ -64,7 +67,15 @@ class ReportEventRestServlet(RestServlet): user_id=user_id, reason=body["reason"], content=body, - received_ts=self.clock.time_msec(), + received_ts=received_ts, + ) + + self.appservice_handler.on_event_report( + room_id=room_id, + event_id=event_id, + user_id=user_id, + body=body, + received_ts=received_ts, ) return 200, {} |