From 42c45e7119ce4efe9f5f9cd28e31bc5b449f9869 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 12 Jul 2022 12:03:34 +0100 Subject: [PATCH 1/2] Notifier: accept callbacks to fire on room joins --- synapse/notifier.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/synapse/notifier.py b/synapse/notifier.py index 54b0ec4b97b4..c42bb8266add 100644 --- a/synapse/notifier.py +++ b/synapse/notifier.py @@ -228,6 +228,7 @@ def __init__(self, hs: "HomeServer"): # Called when there are new things to stream over replication self.replication_callbacks: List[Callable[[], None]] = [] + self._new_join_in_room_callbacks: List[Callable[[str, str], None]] = [] self._federation_client = hs.get_federation_http_client() @@ -280,6 +281,19 @@ def add_replication_callback(self, cb: Callable[[], None]) -> None: """ self.replication_callbacks.append(cb) + def add_new_join_in_room_callback(self, cb: Callable[[str, str], None]) -> None: + """Add a callback that will be called when a user joins a room. + + This only fires on genuine membership changes, e.g. "invite" -> "join". + Membership transitions like "join" -> "join" (for e.g. displayname changes) do + not trigger the callback. + + When called, the callback receives two arguments: the event ID and the room ID. + It should *not* return a Deferred - if it needs to do any asynchronous work, a + background thread should be started and wrapped with run_as_background_process. + """ + self._new_join_in_room_callbacks.append(cb) + async def on_new_room_event( self, event: EventBase, @@ -723,6 +737,10 @@ def notify_replication(self) -> None: for cb in self.replication_callbacks: cb() + def notify_user_joined_room(self, event_id: str, room_id: str) -> None: + for cb in self._new_join_in_room_callbacks: + cb(event_id, room_id) + def notify_remote_server_up(self, server: str) -> None: """Notify any replication that a remote server has come back up""" # We call federation_sender directly rather than registering as a From ddde86a2069adc56a8ef2dece5ce2dd22fa4badd Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 12 Jul 2022 12:11:52 +0100 Subject: [PATCH 2/2] Changelog --- changelog.d/13254.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/13254.misc diff --git a/changelog.d/13254.misc b/changelog.d/13254.misc new file mode 100644 index 000000000000..cba6b9ee0ff0 --- /dev/null +++ b/changelog.d/13254.misc @@ -0,0 +1 @@ +Preparatory work for a per-room rate limiter on joins.