Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Guard processing device list updates with experimental option
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Mar 10, 2022
1 parent 4b67118 commit 51be04b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
5 changes: 3 additions & 2 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ def read_config(self, config: JsonDict, **kwargs):
"msc3202_device_masquerading", False
)

# Portion of MSC3202 related to transaction extensions:
# sending one-time key counts and fallback key usage to application services.
# The portion of MSC3202 related to transaction extensions:
# sending device list changes, one-time key counts and fallback key
# usage to application services.
self.msc3202_transaction_extensions: bool = experimental.get(
"msc3202_transaction_extensions", False
)
Expand Down
36 changes: 31 additions & 5 deletions synapse/handlers/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def __init__(self, hs: "HomeServer"):
self._msc2409_to_device_messages_enabled = (
hs.config.experimental.msc2409_to_device_messages_enabled
)
self._msc3202_transaction_extensions_enabled = (
hs.config.experimental.msc3202_transaction_extensions
)

self.current_max = 0
self.is_processing = False
Expand Down Expand Up @@ -204,9 +207,9 @@ def notify_interested_services_ephemeral(
Args:
stream_key: The stream the event came from.
`stream_key` can be "typing_key", "receipt_key", "presence_key" or
"to_device_key". Any other value for `stream_key` will cause this function
to return early.
`stream_key` can be "typing_key", "receipt_key", "presence_key",
"to_device_key" or "device_list_key". Any other value for `stream_key`
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
Expand All @@ -230,6 +233,7 @@ def notify_interested_services_ephemeral(
"receipt_key",
"presence_key",
"to_device_key",
"device_list_key",
):
return

Expand All @@ -253,15 +257,37 @@ def notify_interested_services_ephemeral(
):
return

# Ignore device lists if the feature flag is not enabled
if (
stream_key == "device_list_key"
and not self._msc3202_transaction_extensions_enabled
):
return

# Check whether there are any appservices which have registered to receive
# ephemeral events.
#
# Note that whether these events are actually relevant to these appservices
# is decided later on.
services = self.store.get_app_services()
services = [
service
for service in self.store.get_app_services()
if service.supports_ephemeral
for service in services
# Different stream keys require different support booleans
if (
stream_key
in (
"typing_key",
"receipt_key",
"presence_key",
"to_device_key",
)
and service.supports_ephemeral
)
or (
stream_key == "device_list_key"
and service.msc3202_transaction_extensions
)
]
if not services:
# Bail out early if none of the target appservices have explicitly registered
Expand Down

0 comments on commit 51be04b

Please sign in to comment.