1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414import logging
15- from typing import TYPE_CHECKING , Tuple
15+ from http import HTTPStatus
16+ from typing import TYPE_CHECKING , Dict , List , Tuple
1617
1718from synapse .api .errors import Codes , SynapseError
1819from synapse .http .server import HttpServer
19- from synapse .http .servlet import RestServlet
20+ from synapse .http .servlet import RestServlet , parse_strings_from_args
2021from synapse .http .site import SynapseRequest
21- from synapse .types import JsonDict , UserID
22+ from synapse .types import JsonDict
2223
2324from ._base import client_patterns
2425
3031
3132class UserMutualRoomsServlet (RestServlet ):
3233 """
33- GET /uk.half-shot.msc2666/user/mutual_rooms/ {user_id} HTTP/1.1
34+ GET /uk.half-shot.msc2666/user/mutual_rooms?user_id= {user_id} HTTP/1.1
3435 """
3536
3637 PATTERNS = client_patterns (
37- "/uk.half-shot.msc2666/user/mutual_rooms/(?P<user_id>[^/]*) " ,
38+ "/uk.half-shot.msc2666/user/mutual_rooms$ " ,
3839 releases = (), # This is an unstable feature
3940 )
4041
@@ -43,17 +44,35 @@ def __init__(self, hs: "HomeServer"):
4344 self .auth = hs .get_auth ()
4445 self .store = hs .get_datastores ().main
4546
46- async def on_GET (
47- self , request : SynapseRequest , user_id : str
48- ) -> Tuple [int , JsonDict ]:
49- UserID .from_string (user_id )
47+ async def on_GET (self , request : SynapseRequest ) -> Tuple [int , JsonDict ]:
48+ # twisted.web.server.Request.args is incorrectly defined as Optional[Any]
49+ args : Dict [bytes , List [bytes ]] = request .args # type: ignore
50+
51+ user_ids = parse_strings_from_args (args , "user_id" , required = True )
52+
53+ if len (user_ids ) > 1 :
54+ raise SynapseError (
55+ HTTPStatus .BAD_REQUEST ,
56+ "Duplicate user_id query parameter" ,
57+ errcode = Codes .INVALID_PARAM ,
58+ )
59+
60+ # We don't do batching, so a batch token is illegal by default
61+ if b"batch_token" in args :
62+ raise SynapseError (
63+ HTTPStatus .BAD_REQUEST ,
64+ "Unknown batch_token" ,
65+ errcode = Codes .INVALID_PARAM ,
66+ )
67+
68+ user_id = user_ids [0 ]
5069
5170 requester = await self .auth .get_user_by_req (request )
5271 if user_id == requester .user .to_string ():
5372 raise SynapseError (
54- code = 400 ,
55- msg = "You cannot request a list of shared rooms with yourself" ,
56- errcode = Codes .FORBIDDEN ,
73+ HTTPStatus . UNPROCESSABLE_ENTITY ,
74+ "You cannot request a list of shared rooms with yourself" ,
75+ errcode = Codes .INVALID_PARAM ,
5776 )
5877
5978 rooms = await self .store .get_mutual_rooms_between_users (
0 commit comments