diff options
author | lukasdenk <63459921+lukasdenk@users.noreply.github.com> | 2022-10-03 14:30:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-03 13:30:45 +0000 |
commit | 719488dda87b04e4650a32f0c2b0b71782e0d48b (patch) | |
tree | 3ed81234b3cc909228f4e03db77b63b42f560b17 /synapse/rest | |
parent | Fix twisted trunk mypy errors (#14012) (diff) | |
download | synapse-719488dda87b04e4650a32f0c2b0b71782e0d48b.tar.xz |
Add query parameter `ts` to allow appservices set the `origin_server_ts` for state events. (#11866)
MSC3316 declares that both /rooms/{roomId}/send and /rooms/{roomId}/state should accept a ts parameter for appservices. This change expands support to /state and adds tests.
Diffstat (limited to 'synapse/rest')
-rw-r--r-- | synapse/rest/client/room.py | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/synapse/rest/client/room.py b/synapse/rest/client/room.py index 0bca012535..b6dedbed04 100644 --- a/synapse/rest/client/room.py +++ b/synapse/rest/client/room.py @@ -268,15 +268,9 @@ class RoomStateEventRestServlet(TransactionRestServlet): content = parse_json_object_from_request(request) - event_dict = { - "type": event_type, - "content": content, - "room_id": room_id, - "sender": requester.user.to_string(), - } - - if state_key is not None: - event_dict["state_key"] = state_key + origin_server_ts = None + if requester.app_service: + origin_server_ts = parse_integer(request, "ts") try: if event_type == EventTypes.Member: @@ -287,8 +281,22 @@ class RoomStateEventRestServlet(TransactionRestServlet): room_id=room_id, action=membership, content=content, + origin_server_ts=origin_server_ts, ) else: + event_dict: JsonDict = { + "type": event_type, + "content": content, + "room_id": room_id, + "sender": requester.user.to_string(), + } + + if state_key is not None: + event_dict["state_key"] = state_key + + if origin_server_ts is not None: + event_dict["origin_server_ts"] = origin_server_ts + ( event, _, @@ -333,10 +341,10 @@ class RoomSendEventRestServlet(TransactionRestServlet): "sender": requester.user.to_string(), } - # Twisted will have processed the args by now. - assert request.args is not None - if b"ts" in request.args and requester.app_service: - event_dict["origin_server_ts"] = parse_integer(request, "ts", 0) + if requester.app_service: + origin_server_ts = parse_integer(request, "ts") + if origin_server_ts is not None: + event_dict["origin_server_ts"] = origin_server_ts try: ( |