Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow override origin_server_ts
Browse files Browse the repository at this point in the history
MadLittleMods committed Jan 30, 2021
1 parent 4836954 commit c0b0936
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scripts-dev/complement.sh
Original file line number Diff line number Diff line change
@@ -17,4 +17,4 @@ cd ../complement
docker build -t complement-synapse -f dockerfiles/Synapse.Dockerfile ./dockerfiles

# Run the tests on the resulting image!
COMPLEMENT_DEBUG=1 COMPLEMENT_BASE_IMAGE=complement-synapse go test -tags msc2716 -v -count=1 ./tests/main_test.go ./tests/msc2716_test.go
COMPLEMENT_BASE_IMAGE=complement-synapse go test -tags msc2716 -v -count=1 ./tests/main_test.go ./tests/msc2716_test.go
3 changes: 2 additions & 1 deletion synapse/http/servlet.py
Original file line number Diff line number Diff line change
@@ -151,6 +151,7 @@ def parse_string(
def parse_string_value(
value,
allowed_values,
name="",
encoding="ascii"
) -> str:
if encoding:
@@ -186,7 +187,7 @@ def parse_strings_from_args(
if name in args:
values = args[name]

return [parse_string_value(value, allowed_values, encoding=encoding) for value in values]
return [parse_string_value(value, allowed_values, name=name, encoding=encoding) for value in values]
else:
if required:
message = "Missing %s query parameter %r" % (param_type, name)
17 changes: 13 additions & 4 deletions synapse/rest/client/v1/room.py
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@
parse_integer,
parse_json_object_from_request,
parse_strings_from_args,
parse_integer_from_args,
parse_string,
)
from synapse.logging.opentracing import set_tag
@@ -224,17 +225,25 @@ async def on_POST(self, request, room_id, event_type, txn_id=None):
requester = await self.auth.get_user_by_req(request, allow_guest=True)
content = parse_json_object_from_request(request)
prev_events = parse_strings_from_args(request.args, "prev_event")

logger.info("prev_events %s", prev_events)
origin_server_ts = parse_integer(request, "origin_server_ts")

event_dict = {
"type": event_type,
"content": content,
"room_id": room_id,
"sender": requester.user.to_string(),
"prev_events": prev_events
"sender": requester.user.to_string()
}

if prev_events:
event_dict["prev_events"] = prev_events

# TODO: Add `and requester.app_service`
if origin_server_ts:
event_dict["origin_server_ts"] = origin_server_ts

# TODO: I noticed in the Synapse code that we already accept a `ts` query parameter to override
# the `origin_server_ts` if the request is coming from an app service.
# Do we want to remove in favor of the spec'ed code above
if b"ts" in request.args and requester.app_service:
event_dict["origin_server_ts"] = parse_integer(request, "ts", 0)

0 comments on commit c0b0936

Please sign in to comment.