@@ -188,7 +188,7 @@ def notify_interested_services_ephemeral(
188
188
self ,
189
189
stream_key : str ,
190
190
new_token : Union [int , RoomStreamToken ],
191
- users : Optional [ Collection [Union [str , UserID ]]] = None ,
191
+ users : Collection [Union [str , UserID ]],
192
192
) -> None :
193
193
"""
194
194
This is called by the notifier in the background when an ephemeral event is handled
@@ -203,7 +203,9 @@ def notify_interested_services_ephemeral(
203
203
value for `stream_key` will cause this function to return early.
204
204
205
205
Ephemeral events will only be pushed to appservices that have opted into
206
- them.
206
+ receiving them by setting `push_ephemeral` to true in their registration
207
+ file. Note that while MSC2409 is experimental, this option is called
208
+ `de.sorunome.msc2409.push_ephemeral`.
207
209
208
210
Appservices will only receive ephemeral events that fall within their
209
211
registered user and room namespaces.
@@ -214,6 +216,7 @@ def notify_interested_services_ephemeral(
214
216
if not self .notify_appservices :
215
217
return
216
218
219
+ # Ignore any unsupported streams
217
220
if stream_key not in ("typing_key" , "receipt_key" , "presence_key" ):
218
221
return
219
222
@@ -230,18 +233,25 @@ def notify_interested_services_ephemeral(
230
233
# Additional context: https://github.com/matrix-org/synapse/pull/11137
231
234
assert isinstance (new_token , int )
232
235
236
+ # Check whether there are any appservices which have registered to receive
237
+ # ephemeral events.
238
+ #
239
+ # Note that whether these events are actually relevant to these appservices
240
+ # is decided later on.
233
241
services = [
234
242
service
235
243
for service in self .store .get_app_services ()
236
244
if service .supports_ephemeral
237
245
]
238
246
if not services :
247
+ # Bail out early if none of the target appservices have explicitly registered
248
+ # to receive these ephemeral events.
239
249
return
240
250
241
251
# We only start a new background process if necessary rather than
242
252
# optimistically (to cut down on overhead).
243
253
self ._notify_interested_services_ephemeral (
244
- services , stream_key , new_token , users or []
254
+ services , stream_key , new_token , users
245
255
)
246
256
247
257
@wrap_as_background_process ("notify_interested_services_ephemeral" )
@@ -252,7 +262,7 @@ async def _notify_interested_services_ephemeral(
252
262
new_token : int ,
253
263
users : Collection [Union [str , UserID ]],
254
264
) -> None :
255
- logger .debug ("Checking interested services for %s" % ( stream_key ) )
265
+ logger .debug ("Checking interested services for %s" , stream_key )
256
266
with Measure (self .clock , "notify_interested_services_ephemeral" ):
257
267
for service in services :
258
268
if stream_key == "typing_key" :
@@ -345,6 +355,9 @@ async def _handle_receipts(
345
355
346
356
Args:
347
357
service: The application service to check for which events it should receive.
358
+ new_token: A receipts event stream token. Purely used to double-check that the
359
+ from_token we pull from the database isn't greater than or equal to this
360
+ token. Prevents accidentally duplicating work.
348
361
349
362
Returns:
350
363
A list of JSON dictionaries containing data derived from the read receipts that
@@ -382,6 +395,9 @@ async def _handle_presence(
382
395
Args:
383
396
service: The application service that ephemeral events are being sent to.
384
397
users: The users that should receive the presence update.
398
+ new_token: A presence update stream token. Purely used to double-check that the
399
+ from_token we pull from the database isn't greater than or equal to this
400
+ token. Prevents accidentally duplicating work.
385
401
386
402
Returns:
387
403
A list of json dictionaries containing data derived from the presence events
0 commit comments