Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/19758.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stabilize support for sending ephemeral events to application services, as per [MSC2409](https://github.com/matrix-org/matrix-spec-proposals/pull/2409). Contribute by @jason-famedly @ Famedly.
2 changes: 2 additions & 0 deletions synapse/appservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def __init__(
rate_limited: bool = True,
ip_range_whitelist: IPSet | None = None,
supports_ephemeral: bool = False,
supports_unstable_ephemeral: bool = False,
msc3202_transaction_extensions: bool = False,
msc4190_device_management: bool = False,
):
Expand All @@ -125,6 +126,7 @@ def __init__(
self.namespaces = self._check_namespaces(namespaces)
self.id = id
self.ip_range_whitelist = ip_range_whitelist
self.supports_unstable_ephemeral = supports_unstable_ephemeral
self.supports_ephemeral = supports_ephemeral
self.msc3202_transaction_extensions = msc3202_transaction_extensions
self.msc4190_device_management = msc4190_device_management
Expand Down
15 changes: 14 additions & 1 deletion synapse/appservice/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,21 @@ async def push_bulk(
if service.supports_ephemeral:
body.update(
{
# TODO: Update to stable prefixes once MSC2409 completes FCP merge.
"ephemeral": ephemeral,
}
)
if service.supports_unstable_ephemeral:
body.update(
{
"de.sorunome.msc2409.ephemeral": ephemeral,
}
)
if service.supports_ephemeral or service.supports_unstable_ephemeral:
body.update(
{
# TODO: Update to stable prefixes once MSC4203 completes FCP merge.
# Previously, this was part of MSC2409 which is why it has the
# mismatched unstable identifier
Comment on lines +360 to +374
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how we handled that in the past, but I feel like we should continue sending the unstable identifier to avoid breaking application services which only support the unstable prefix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. That is fair. Do you think using the change in the configuration setting should be the decider on which identifier should be sent? So that if the config says receive_ephemeral it would provide the stable key, but if it was de.sorunome.msc2409.push_ephemeral it would use the older unstable key? Or do you suppose just sending both each time?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave the first option a try in 5c76d3f.

As a note: the existing code did not do the optional exclusion of the key if there was no relevant data. Would you be interested in that here, or push it to later?

"de.sorunome.msc2409.to_device": to_device_messages,
}
)
Expand Down
8 changes: 7 additions & 1 deletion synapse/config/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ def _load_appservice(
if as_info.get("ip_range_whitelist"):
ip_range_whitelist = IPSet(as_info.get("ip_range_whitelist"))

supports_ephemeral = as_info.get("de.sorunome.msc2409.push_ephemeral", False)
# TODO: remove push_ephemeral handling at some point in the future. It was part of
# MSC2409 which changed the identifier near the end of the review cycle.
supports_unstable_ephemeral = as_info.get(
"de.sorunome.msc2409.push_ephemeral", False
)
supports_ephemeral = as_info.get("receive_ephemeral", False)

# Opt-in flag for the MSC3202-specific transactional behaviour.
# When enabled, appservice transactions contain the following information:
Expand Down Expand Up @@ -204,6 +209,7 @@ def _load_appservice(
protocols=protocols,
rate_limited=rate_limited,
ip_range_whitelist=ip_range_whitelist,
supports_unstable_ephemeral=supports_unstable_ephemeral,
supports_ephemeral=supports_ephemeral,
msc3202_transaction_extensions=msc3202_transaction_extensions,
msc4190_device_management=msc4190_enabled,
Expand Down
2 changes: 2 additions & 0 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ def read_config(
# MSC2409 (this setting only relates to optionally sending to-device messages).
# Presence, typing and read receipt EDUs are already sent to application services that
# have opted in to receive them. If enabled, this adds to-device messages to that list.
# This is also for MSC4203 which was broken off of MSC2409 but kept the same unstable
# identifier.
self.msc2409_to_device_messages_enabled: bool = experimental.get(
"msc2409_to_device_messages_enabled", False
)
Expand Down
6 changes: 2 additions & 4 deletions synapse/handlers/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,8 @@ def notify_interested_services_ephemeral(
will cause this function to return early.

Ephemeral events will only be pushed to appservices that have opted into
receiving them by setting `push_ephemeral` to true in their registration
file. Note that while MSC2409 is experimental, this option is called
`de.sorunome.msc2409.push_ephemeral`.
receiving them by setting `receive_ephemeral` to true in their
registration file(previously this was `push_ephemeral`).

Appservices will only receive ephemeral events that fall within their
registered user and room namespaces.
Expand All @@ -270,7 +269,6 @@ def notify_interested_services_ephemeral(

# Notify appservices of updates in ephemeral event streams.
# Only the following streams are currently supported.
# FIXME: We should use constants for these values.
if stream_key not in (
StreamKeyType.TYPING,
StreamKeyType.RECEIPT,
Expand Down
Loading