Stabilise MSC2409 support: send ephemeral events to appservices

This commit is contained in:
Quentin Gliech
2025-06-02 15:51:56 +02:00
parent 2436512a25
commit b3428806e2
5 changed files with 35 additions and 9 deletions

View File

@@ -85,7 +85,8 @@ class ApplicationService:
protocols: Optional[Iterable[str]] = None,
rate_limited: bool = True,
ip_range_whitelist: Optional[IPSet] = None,
supports_ephemeral: bool = False,
receive_ephemeral: bool = False,
msc2409_push_ephemeral: bool = False,
msc3202_transaction_extensions: bool = False,
msc4190_device_management: bool = False,
):
@@ -99,7 +100,8 @@ class ApplicationService:
self.namespaces = self._check_namespaces(namespaces)
self.id = id
self.ip_range_whitelist = ip_range_whitelist
self.supports_ephemeral = supports_ephemeral
self.receive_ephemeral = receive_ephemeral
self.msc2409_push_ephemeral = msc2409_push_ephemeral
self.msc3202_transaction_extensions = msc3202_transaction_extensions
self.msc4190_device_management = msc4190_device_management

View File

@@ -350,7 +350,7 @@ class ApplicationServiceApi(SimpleHttpClient):
# Never send ephemeral events to appservices that do not support it
body: JsonDict = {"events": serialized_events}
if service.supports_ephemeral:
if service.msc2409_push_ephemeral:
body.update(
{
# TODO: Update to stable prefixes once MSC2409 completes FCP merge.
@@ -359,6 +359,13 @@ class ApplicationServiceApi(SimpleHttpClient):
}
)
if service.receive_ephemeral:
body.update(
{
"ephemeral": ephemeral,
}
)
# TODO: Update to stable prefixes once MSC3202 completes FCP merge
if service.msc3202_transaction_extensions:
if one_time_keys_count:

View File

@@ -170,7 +170,19 @@ 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)
unstable_msc2409_supports_ephemeral = as_info.get(
"de.sorunome.msc2409.push_ephemeral", False
)
if not isinstance(unstable_msc2409_supports_ephemeral, bool):
raise ValueError(
"The `de.sorunome.msc2409.push_ephemeral` option should be true or false if specified."
)
receive_ephemeral = as_info.get("receive_ephemeral", False)
if not isinstance(receive_ephemeral, bool):
raise ValueError(
"The `receive_ephemeral` option should be true or false if specified."
)
# Opt-in flag for the MSC3202-specific transactional behaviour.
# When enabled, appservice transactions contain the following information:
@@ -205,7 +217,8 @@ def _load_appservice(
protocols=protocols,
rate_limited=rate_limited,
ip_range_whitelist=ip_range_whitelist,
supports_ephemeral=supports_ephemeral,
receive_ephemeral=receive_ephemeral,
msc2409_push_ephemeral=unstable_msc2409_supports_ephemeral,
msc3202_transaction_extensions=msc3202_transaction_extensions,
msc4190_device_management=msc4190_enabled,
)

View File

@@ -300,9 +300,13 @@ class ApplicationServicesHandler:
StreamKeyType.TYPING,
StreamKeyType.RECEIPT,
StreamKeyType.PRESENCE,
StreamKeyType.TO_DEVICE,
)
and service.supports_ephemeral
and (service.receive_ephemeral or service.msc2409_push_ephemeral)
)
# A previous version of MSC2409 supported sending to-device messages
# to the appservice, but this was removed in the stable version.
or (
stream_key == StreamKeyType.TO_DEVICE and service.msc2409_push_ephemeral
)
or (
stream_key == StreamKeyType.DEVICE_LIST

View File

@@ -1012,7 +1012,7 @@ class ApplicationServicesHandlerSendEventsTestCase(unittest.HomeserverTestCase):
sender="@as:example.com",
rate_limited=False,
namespaces=namespaces,
supports_ephemeral=True,
receive_ephemeral=True,
)
# Register the application service
@@ -1097,7 +1097,7 @@ class ApplicationServicesHandlerDeviceListsTestCase(unittest.HomeserverTestCase)
}
],
},
supports_ephemeral=True,
receive_ephemeral=True,
msc3202_transaction_extensions=as_supports_txn_extensions,
# Must be set for Synapse to try pushing data to the AS
hs_token="abcde",