Skip to content
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

Stabilize MSC2409 (Send typing, presence and receipts to appservices) #17881

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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/17881.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stabilize MSC2409 (Send typing, presence and receipts to appservices).
2 changes: 2 additions & 0 deletions synapse/appservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def __init__(
rate_limited: bool = True,
ip_range_whitelist: Optional[IPSet] = None,
supports_ephemeral: bool = False,
supports_ephemeral_legacy: bool = False,
msc3202_transaction_extensions: bool = False,
):
self.token = token
Expand All @@ -99,6 +100,7 @@ def __init__(
self.id = id
self.ip_range_whitelist = ip_range_whitelist
self.supports_ephemeral = supports_ephemeral
self.supports_ephemeral_legacy = supports_ephemeral_legacy
self.msc3202_transaction_extensions = msc3202_transaction_extensions

if "|" in self.id:
Expand Down
11 changes: 10 additions & 1 deletion synapse/appservice/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,16 @@ async def push_bulk(
if service.supports_ephemeral:
body.update(
{
# TODO: Update to stable prefixes once MSC2409 completes FCP merge.
"ephemeral": ephemeral,
# NOTE: This is actually https://github.com/matrix-org/matrix-spec-proposals/blob/tulir/appservice-to-device/proposals/4203-appservice-to-device.md
# but for legacy reasons uses an older MSC number.
"de.sorunome.msc2409.to_device": to_device_messages,
Copy link
Member Author

Choose a reason for hiding this comment

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

I was unsure whether this should be included if the AS opts into the stable flag in it's registration file, but on balance I think this would cause us to have to maintain the legacy flag for the sake of ASes that want to have to-device messages.

This field is still only populated if the homeserver opts into MSC4203, so it's not like we're ever emitting unstable information on a stable HS.

}
)
elif service.supports_ephemeral_legacy:
Copy link
Member Author

Choose a reason for hiding this comment

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

I've chosen to keep the old fields around for a bit to allow ASes to migrate, but at some point this will need to be deprecated.

Copy link
Contributor

@tulir tulir Oct 28, 2024

Choose a reason for hiding this comment

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

This might need to be a bigger note in changelogs when it's deprecated/removed, because ASes can't update registrations themselves, server admins have to do it manually

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, sounds reasonable. Worth putting in the upgrade notes too.

# Support to be removed in a future spec version.
body.update(
{
"de.sorunome.msc2409.ephemeral": ephemeral,
"de.sorunome.msc2409.to_device": to_device_messages,
}
Expand Down
10 changes: 9 additions & 1 deletion synapse/config/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,14 @@ 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)
supports_ephemeral = as_info.get("receive_ephemeral", False)

# For ASes that haven't transitioned to the stable fields yet
supports_ephemeral_legacy = False
if not supports_ephemeral:
supports_ephemeral_legacy = as_info.get(
"de.sorunome.msc2409.push_ephemeral", False
)

# Opt-in flag for the MSC3202-specific transactional behaviour.
# When enabled, appservice transactions contain the following information:
Expand All @@ -194,5 +201,6 @@ def _load_appservice(
rate_limited=rate_limited,
ip_range_whitelist=ip_range_whitelist,
supports_ephemeral=supports_ephemeral,
supports_ephemeral_legacy=supports_ephemeral_legacy,
msc3202_transaction_extensions=msc3202_transaction_extensions,
)
6 changes: 4 additions & 2 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,12 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
# MSC3266 (room summary api)
self.msc3266_enabled: bool = experimental.get("msc3266_enabled", False)

# MSC2409 (this setting only relates to optionally sending to-device messages).
# MSC4203 (Sending to-device events to appservices).
# NOTE: This used to be used to be part of MSC2409 but was split out, hence the config
# key not matching the MSC.
# 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.
self.msc2409_to_device_messages_enabled: bool = experimental.get(
self.msc4203_to_device_messages_enabled: bool = experimental.get(
"msc2409_to_device_messages_enabled", False
)

Expand Down
13 changes: 6 additions & 7 deletions synapse/handlers/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def __init__(self, hs: "HomeServer"):
self.clock = hs.get_clock()
self.notify_appservices = hs.config.worker.should_notify_appservices
self.event_sources = hs.get_event_sources()
self._msc2409_to_device_messages_enabled = (
hs.config.experimental.msc2409_to_device_messages_enabled
self._msc4203_to_device_messages_enabled = (
hs.config.experimental.msc4203_to_device_messages_enabled
)
self._msc3202_transaction_extensions_enabled = (
hs.config.experimental.msc3202_transaction_extensions
Expand Down Expand Up @@ -242,9 +242,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 `recieve_ephemeral` to true in their registration
file.

Appservices will only receive ephemeral events that fall within their
registered user and room namespaces.
Expand All @@ -270,7 +269,7 @@ def notify_interested_services_ephemeral(
# Ignore to-device messages if the feature flag is not enabled
if (
stream_key == StreamKeyType.TO_DEVICE
and not self._msc2409_to_device_messages_enabled
and not self._msc4203_to_device_messages_enabled
):
return

Expand Down Expand Up @@ -588,7 +587,7 @@ async def _get_to_device_messages(
new_token,
)

# According to MSC2409, we'll need to add 'to_user_id' and 'to_device_id' fields
# According to MSC4203, we'll need to add 'to_user_id' and 'to_device_id' fields
# to the event JSON so that the application service will know which user/device
# combination this messages was intended for.
#
Expand Down
Loading