-
Notifications
You must be signed in to change notification settings - Fork 503
MSC4140: put delay_id in unsigned data for sender #19479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
052845f
f421b65
fede9e4
eca7871
2e863d6
2774815
8c24226
d699205
453fb12
774e1ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| MSC4140: When persisting a delayed event to the timeline, include its `delay_id` in the event's `unsigned` section in `/sync` responses to the event sender. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -412,7 +412,7 @@ class SerializeEventConfig: | |
| # Function to convert from federation format to client format | ||
| event_format: Callable[[JsonDict], JsonDict] = format_event_for_client_v1 | ||
| # The entity that requested the event. This is used to determine whether to include | ||
| # the transaction_id in the unsigned section of the event. | ||
| # the transaction_id and delay_id in the unsigned section of the event. | ||
| requester: Requester | None = None | ||
| # List of event fields to include. If empty, all fields will be returned. | ||
| only_event_fields: list[str] | None = None | ||
|
|
@@ -475,12 +475,13 @@ def serialize_event( | |
| config=config, | ||
| ) | ||
|
|
||
| # If we have a txn_id saved in the internal_metadata, we should include it in the | ||
| # unsigned section of the event if it was sent by the same session as the one | ||
| # If we have applicable fields saved in the internal_metadata, include them in the | ||
| # unsigned section of the event if the event was sent by the same session as the one | ||
| # requesting the event. | ||
| txn_id: str | None = getattr(e.internal_metadata, "txn_id", None) | ||
| delay_id: str | None = getattr(e.internal_metadata, "delay_id", None) | ||
|
||
| if ( | ||
|
||
| txn_id is not None | ||
| (txn_id is not None or delay_id is not None) | ||
| and config.requester is not None | ||
| and config.requester.user.to_string() == e.sender | ||
| ): | ||
|
|
@@ -491,7 +492,10 @@ def serialize_event( | |
| event_device_id: str | None = getattr(e.internal_metadata, "device_id", None) | ||
| if event_device_id is not None: | ||
| if event_device_id == config.requester.device_id: | ||
| d["unsigned"]["transaction_id"] = txn_id | ||
| if txn_id is not None: | ||
| d["unsigned"]["transaction_id"] = txn_id | ||
| if delay_id is not None: | ||
| d["unsigned"]["delay_id"] = delay_id | ||
|
||
|
|
||
| else: | ||
| # Fallback behaviour: only include the transaction ID if the event | ||
|
|
@@ -512,7 +516,10 @@ def serialize_event( | |
| or config.requester.is_guest | ||
| or config.requester.app_service | ||
| ): | ||
| d["unsigned"]["transaction_id"] = txn_id | ||
| if txn_id is not None: | ||
| d["unsigned"]["transaction_id"] = txn_id | ||
| if delay_id is not None: | ||
| d["unsigned"]["delay_id"] = delay_id | ||
|
|
||
| # invite_room_state and knock_room_state are a list of stripped room state events | ||
| # that are meant to provide metadata about a room to an invitee/knocker. They are | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,8 @@ class EventInternalMetadata: | |||||
|
|
||||||
| txn_id: str | ||||||
| """The transaction ID, if it was set when the event was created.""" | ||||||
| delay_id: str | ||||||
|
Contributor
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'm not sure everything else in this file does it correctly right now, but I would be in favour of making this optional
Suggested change
This will also involve changing the Rust part to return Nones when needed. I'm not dead-set on this, so open to your thoughts? But it seems like it is more typechecker-friendly this way.
Member
Author
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. My vote is to leave this as it is for now, as much as I appreciate proper typing, because there appears to be some nuance to this that I don't fully grasp at the moment & am hesitant to muck around with. From what I can gather from the Rust code, there are some fields in the metadata object that are always present but may set to So, it looks like there is a functional difference between the not-typed-as-optional fields that Python code looks up with |
||||||
| """The delay ID, set only if the event was a delayed event.""" | ||||||
| token_id: int | ||||||
| """The access token ID of the user who sent this event, if any.""" | ||||||
| device_id: str | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.