This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Split out /batch_send
meta events to their own fields (MSC2716)
#10777
Merged
erikjohnston
merged 7 commits into
develop
from
madlittlemods/2716-split-out-meta-response-fields
Sep 15, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c5453df
Split out /batch_send meta properties to their own fields
MadLittleMods 341b873
Add changelog
MadLittleMods e8a90e9
Fix linting
MadLittleMods b411a77
More understandable array slicing and dicing
MadLittleMods 3499f6c
Merge branch 'develop' into madlittlemods/2716-split-out-meta-respons…
MadLittleMods 1a28421
Merge branch 'develop' into madlittlemods/2716-split-out-meta-respons…
MadLittleMods 1b53a6b
Merge branch 'develop' into madlittlemods/2716-split-out-meta-respons…
MadLittleMods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Split out [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716) meta events to their own fields in the `/batch_send` response. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
import logging | ||
import re | ||
from http import HTTPStatus | ||
from typing import TYPE_CHECKING, Awaitable, List, Tuple | ||
|
||
from twisted.web.server import Request | ||
|
@@ -179,7 +180,7 @@ async def on_POST( | |
|
||
if not requester.app_service: | ||
raise AuthError( | ||
403, | ||
HTTPStatus.FORBIDDEN, | ||
"Only application services can use the /batchsend endpoint", | ||
) | ||
|
||
|
@@ -192,7 +193,7 @@ async def on_POST( | |
|
||
if prev_events_from_query is None: | ||
raise SynapseError( | ||
400, | ||
HTTPStatus.BAD_REQUEST, | ||
"prev_event query parameter is required when inserting historical messages back in time", | ||
errcode=Codes.MISSING_PARAM, | ||
) | ||
|
@@ -213,7 +214,7 @@ async def on_POST( | |
prev_state_ids = list(prev_state_map.values()) | ||
auth_event_ids = prev_state_ids | ||
|
||
state_events_at_start = [] | ||
state_event_ids_at_start = [] | ||
for state_event in body["state_events_at_start"]: | ||
assert_params_in_dict( | ||
state_event, ["type", "origin_server_ts", "content", "sender"] | ||
|
@@ -279,7 +280,7 @@ async def on_POST( | |
) | ||
event_id = event.event_id | ||
|
||
state_events_at_start.append(event_id) | ||
state_event_ids_at_start.append(event_id) | ||
auth_event_ids.append(event_id) | ||
|
||
events_to_create = body["events"] | ||
|
@@ -424,20 +425,26 @@ async def on_POST( | |
context=context, | ||
) | ||
|
||
# Add the base_insertion_event to the bottom of the list we return | ||
if base_insertion_event is not None: | ||
event_ids.append(base_insertion_event.event_id) | ||
insertion_event_id = event_ids[0] | ||
chunk_event_id = event_ids[-1] | ||
historical_event_ids = event_ids[1:-1] | ||
|
||
return 200, { | ||
"state_events": state_events_at_start, | ||
"events": event_ids, | ||
response_dict = { | ||
"state_event_ids": state_event_ids_at_start, | ||
"event_ids": historical_event_ids, | ||
"next_chunk_id": insertion_event["content"][ | ||
EventContentFields.MSC2716_NEXT_CHUNK_ID | ||
], | ||
"insertion_event_id": insertion_event_id, | ||
"chunk_event_id": chunk_event_id, | ||
} | ||
if base_insertion_event is not None: | ||
response_dict["base_insertion_event_id"] = base_insertion_event.event_id | ||
|
||
return HTTPStatus.OK, response_dict | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I started using |
||
|
||
def on_GET(self, request: Request, room_id: str) -> Tuple[int, str]: | ||
return 501, "Not implemented" | ||
return HTTPStatus.NOT_IMPLEMENTED, "Not implemented" | ||
|
||
def on_PUT( | ||
self, request: SynapseRequest, room_id: str | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated to this PR, but this method really needs splitting up. I shouldn't have to scroll through over 200 lines to find out where a variable is used!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Definitely. I've been holding off on refactors like this while so many PRs have been in flight at the same time 😬