mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-13 17:13:44 +01:00
Add support for knocking to workers. (#15133)
This commit is contained in:
parent
c8665dd25d
commit
ecbe0ddbe7
9 changed files with 15 additions and 16 deletions
1
changelog.d/15133.feature
Normal file
1
changelog.d/15133.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Add support for knocking to workers.
|
|
@ -205,6 +205,7 @@ WORKERS_CONFIG: Dict[str, Dict[str, Any]] = {
|
||||||
"^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/send",
|
"^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/send",
|
||||||
"^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$",
|
"^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$",
|
||||||
"^/_matrix/client/(api/v1|r0|v3|unstable)/join/",
|
"^/_matrix/client/(api/v1|r0|v3|unstable)/join/",
|
||||||
|
"^/_matrix/client/(api/v1|r0|v3|unstable)/knock/",
|
||||||
"^/_matrix/client/(api/v1|r0|v3|unstable)/profile/",
|
"^/_matrix/client/(api/v1|r0|v3|unstable)/profile/",
|
||||||
"^/_matrix/client/(v1|unstable/org.matrix.msc2716)/rooms/.*/batch_send",
|
"^/_matrix/client/(v1|unstable/org.matrix.msc2716)/rooms/.*/batch_send",
|
||||||
],
|
],
|
||||||
|
|
|
@ -252,6 +252,7 @@ information.
|
||||||
^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/state/
|
^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/state/
|
||||||
^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$
|
^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$
|
||||||
^/_matrix/client/(api/v1|r0|v3|unstable)/join/
|
^/_matrix/client/(api/v1|r0|v3|unstable)/join/
|
||||||
|
^/_matrix/client/(api/v1|r0|v3|unstable)/knock/
|
||||||
^/_matrix/client/(api/v1|r0|v3|unstable)/profile/
|
^/_matrix/client/(api/v1|r0|v3|unstable)/profile/
|
||||||
|
|
||||||
# Account data requests
|
# Account data requests
|
||||||
|
|
|
@ -207,6 +207,7 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
async def remote_knock(
|
async def remote_knock(
|
||||||
self,
|
self,
|
||||||
|
requester: Requester,
|
||||||
remote_room_hosts: List[str],
|
remote_room_hosts: List[str],
|
||||||
room_id: str,
|
room_id: str,
|
||||||
user: UserID,
|
user: UserID,
|
||||||
|
@ -1073,7 +1074,7 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
|
||||||
)
|
)
|
||||||
|
|
||||||
return await self.remote_knock(
|
return await self.remote_knock(
|
||||||
remote_room_hosts, room_id, target, content
|
requester, remote_room_hosts, room_id, target, content
|
||||||
)
|
)
|
||||||
|
|
||||||
return await self._local_membership_update(
|
return await self._local_membership_update(
|
||||||
|
@ -1984,6 +1985,7 @@ class RoomMemberMasterHandler(RoomMemberHandler):
|
||||||
|
|
||||||
async def remote_knock(
|
async def remote_knock(
|
||||||
self,
|
self,
|
||||||
|
requester: Requester,
|
||||||
remote_room_hosts: List[str],
|
remote_room_hosts: List[str],
|
||||||
room_id: str,
|
room_id: str,
|
||||||
user: UserID,
|
user: UserID,
|
||||||
|
|
|
@ -113,6 +113,7 @@ class RoomMemberWorkerHandler(RoomMemberHandler):
|
||||||
|
|
||||||
async def remote_knock(
|
async def remote_knock(
|
||||||
self,
|
self,
|
||||||
|
requester: Requester,
|
||||||
remote_room_hosts: List[str],
|
remote_room_hosts: List[str],
|
||||||
room_id: str,
|
room_id: str,
|
||||||
user: UserID,
|
user: UserID,
|
||||||
|
@ -123,9 +124,10 @@ class RoomMemberWorkerHandler(RoomMemberHandler):
|
||||||
Implements RoomMemberHandler.remote_knock
|
Implements RoomMemberHandler.remote_knock
|
||||||
"""
|
"""
|
||||||
ret = await self._remote_knock_client(
|
ret = await self._remote_knock_client(
|
||||||
|
requester=requester,
|
||||||
remote_room_hosts=remote_room_hosts,
|
remote_room_hosts=remote_room_hosts,
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
user=user,
|
user_id=user.to_string(),
|
||||||
content=content,
|
content=content,
|
||||||
)
|
)
|
||||||
return ret["event_id"], ret["stream_id"]
|
return ret["event_id"], ret["stream_id"]
|
||||||
|
|
|
@ -142,17 +142,12 @@ class ReplicationRemoteKnockRestServlet(ReplicationEndpoint):
|
||||||
}
|
}
|
||||||
|
|
||||||
async def _handle_request( # type: ignore[override]
|
async def _handle_request( # type: ignore[override]
|
||||||
self,
|
self, request: SynapseRequest, content: JsonDict, room_id: str, user_id: str
|
||||||
request: SynapseRequest,
|
|
||||||
content: JsonDict,
|
|
||||||
room_id: str,
|
|
||||||
user_id: str,
|
|
||||||
) -> Tuple[int, JsonDict]:
|
) -> Tuple[int, JsonDict]:
|
||||||
remote_room_hosts = content["remote_room_hosts"]
|
remote_room_hosts = content["remote_room_hosts"]
|
||||||
event_content = content["content"]
|
event_content = content["content"]
|
||||||
|
|
||||||
requester = Requester.deserialize(self.store, content["requester"])
|
requester = Requester.deserialize(self.store, content["requester"])
|
||||||
|
|
||||||
request.requester = requester
|
request.requester = requester
|
||||||
|
|
||||||
logger.debug("remote_knock: %s on room: %s", user_id, room_id)
|
logger.debug("remote_knock: %s on room: %s", user_id, room_id)
|
||||||
|
@ -277,16 +272,12 @@ class ReplicationRemoteRescindKnockRestServlet(ReplicationEndpoint):
|
||||||
}
|
}
|
||||||
|
|
||||||
async def _handle_request( # type: ignore[override]
|
async def _handle_request( # type: ignore[override]
|
||||||
self,
|
self, request: SynapseRequest, content: JsonDict, knock_event_id: str
|
||||||
request: SynapseRequest,
|
|
||||||
content: JsonDict,
|
|
||||||
knock_event_id: str,
|
|
||||||
) -> Tuple[int, JsonDict]:
|
) -> Tuple[int, JsonDict]:
|
||||||
txn_id = content["txn_id"]
|
txn_id = content["txn_id"]
|
||||||
event_content = content["content"]
|
event_content = content["content"]
|
||||||
|
|
||||||
requester = Requester.deserialize(self.store, content["requester"])
|
requester = Requester.deserialize(self.store, content["requester"])
|
||||||
|
|
||||||
request.requester = requester
|
request.requester = requester
|
||||||
|
|
||||||
# hopefully we're now on the master, so this won't recurse!
|
# hopefully we're now on the master, so this won't recurse!
|
||||||
|
@ -363,3 +354,5 @@ def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
|
||||||
ReplicationRemoteJoinRestServlet(hs).register(http_server)
|
ReplicationRemoteJoinRestServlet(hs).register(http_server)
|
||||||
ReplicationRemoteRejectInviteRestServlet(hs).register(http_server)
|
ReplicationRemoteRejectInviteRestServlet(hs).register(http_server)
|
||||||
ReplicationUserJoinedLeftRoomRestServlet(hs).register(http_server)
|
ReplicationUserJoinedLeftRoomRestServlet(hs).register(http_server)
|
||||||
|
ReplicationRemoteKnockRestServlet(hs).register(http_server)
|
||||||
|
ReplicationRemoteRescindKnockRestServlet(hs).register(http_server)
|
||||||
|
|
|
@ -63,7 +63,6 @@ class KnockRoomAliasServlet(RestServlet):
|
||||||
|
|
||||||
# twisted.web.server.Request.args is incorrectly defined as Optional[Any]
|
# twisted.web.server.Request.args is incorrectly defined as Optional[Any]
|
||||||
args: Dict[bytes, List[bytes]] = request.args # type: ignore
|
args: Dict[bytes, List[bytes]] = request.args # type: ignore
|
||||||
|
|
||||||
remote_room_hosts = parse_strings_from_args(
|
remote_room_hosts = parse_strings_from_args(
|
||||||
args, "server_name", required=False
|
args, "server_name", required=False
|
||||||
)
|
)
|
||||||
|
|
|
@ -926,7 +926,7 @@ class RoomMembershipRestServlet(TransactionRestServlet):
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
|
|
||||||
def register(self, http_server: HttpServer) -> None:
|
def register(self, http_server: HttpServer) -> None:
|
||||||
# /rooms/$roomid/[invite|join|leave]
|
# /rooms/$roomid/[join|invite|leave|ban|unban|kick]
|
||||||
PATTERNS = (
|
PATTERNS = (
|
||||||
"/rooms/(?P<room_id>[^/]*)/"
|
"/rooms/(?P<room_id>[^/]*)/"
|
||||||
"(?P<membership_action>join|invite|leave|ban|unban|kick)"
|
"(?P<membership_action>join|invite|leave|ban|unban|kick)"
|
||||||
|
|
Loading…
Reference in a new issue