diff --git a/synapse/replication/http/push.py b/synapse/replication/http/push.py
index 8e5641707a..de07e75b46 100644
--- a/synapse/replication/http/push.py
+++ b/synapse/replication/http/push.py
@@ -77,5 +77,46 @@ class ReplicationRemovePusherRestServlet(ReplicationEndpoint):
return 200, {}
+class ReplicationCopyPusherRestServlet(ReplicationEndpoint):
+ """Copies push rules from an old room to new room.
+
+ Request format:
+
+ POST /_synapse/replication/copy_push_rules/:user_id/:old_room_id/:new_room_id
+
+ {}
+
+ """
+
+ NAME = "copy_push_rules"
+ PATH_ARGS = ("user_id", "old_room_id", "new_room_id")
+ CACHE = False
+
+ def __init__(self, hs: "HomeServer"):
+ super().__init__(hs)
+
+ self._store = hs.get_datastores().main
+
+ @staticmethod
+ async def _serialize_payload(user_id: str, old_room_id: str, new_room_id: str) -> JsonDict: # type: ignore[override]
+ return {}
+
+ async def _handle_request( # type: ignore[override]
+ self,
+ request: Request,
+ content: JsonDict,
+ user_id: str,
+ old_room_id: str,
+ new_room_id: str,
+ ) -> Tuple[int, JsonDict]:
+
+ await self._store.copy_push_rules_from_room_to_room_for_user(
+ old_room_id, new_room_id, user_id
+ )
+
+ return 200, {}
+
+
def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
ReplicationRemovePusherRestServlet(hs).register(http_server)
+ ReplicationCopyPusherRestServlet(hs).register(http_server)
diff --git a/synapse/replication/tcp/handler.py b/synapse/replication/tcp/handler.py
index ecc12c0b28..4342d6ce70 100644
--- a/synapse/replication/tcp/handler.py
+++ b/synapse/replication/tcp/handler.py
@@ -66,6 +66,7 @@ from synapse.replication.tcp.streams import (
FederationStream,
PresenceFederationStream,
PresenceStream,
+ PushRulesStream,
ReceiptsStream,
Stream,
ToDeviceStream,
@@ -178,6 +179,12 @@ class ReplicationCommandHandler:
continue
+ if isinstance(stream, PushRulesStream):
+ if hs.get_instance_name() in hs.config.worker.writers.push:
+ self._streams_to_replicate.append(stream)
+
+ continue
+
# Only add any other streams if we're on master.
if hs.config.worker.worker_app is not None:
continue
|