38
38
JsonDict ,
39
39
RoomAlias ,
40
40
RoomStreamToken ,
41
+ StreamKeyType ,
41
42
UserID ,
42
43
)
43
44
from synapse .util .async_helpers import Linearizer
@@ -213,8 +214,8 @@ def notify_interested_services_ephemeral(
213
214
Args:
214
215
stream_key: The stream the event came from.
215
216
216
- `stream_key` can be "typing_key", "receipt_key", "presence_key" ,
217
- "to_device_key" or "device_list_key" . Any other value for `stream_key`
217
+ `stream_key` can be StreamKeyType.TYPING, StreamKeyType.RECEIPT, StreamKeyType.PRESENCE ,
218
+ StreamKeyType.TO_DEVICE or StreamKeyType.DEVICE_LIST . Any other value for `stream_key`
218
219
will cause this function to return early.
219
220
220
221
Ephemeral events will only be pushed to appservices that have opted into
@@ -235,11 +236,11 @@ def notify_interested_services_ephemeral(
235
236
# Only the following streams are currently supported.
236
237
# FIXME: We should use constants for these values.
237
238
if stream_key not in (
238
- "typing_key" ,
239
- "receipt_key" ,
240
- "presence_key" ,
241
- "to_device_key" ,
242
- "device_list_key" ,
239
+ StreamKeyType . TYPING ,
240
+ StreamKeyType . RECEIPT ,
241
+ StreamKeyType . PRESENCE ,
242
+ StreamKeyType . TO_DEVICE ,
243
+ StreamKeyType . DEVICE_LIST ,
243
244
):
244
245
return
245
246
@@ -258,14 +259,14 @@ def notify_interested_services_ephemeral(
258
259
259
260
# Ignore to-device messages if the feature flag is not enabled
260
261
if (
261
- stream_key == "to_device_key"
262
+ stream_key == StreamKeyType . TO_DEVICE
262
263
and not self ._msc2409_to_device_messages_enabled
263
264
):
264
265
return
265
266
266
267
# Ignore device lists if the feature flag is not enabled
267
268
if (
268
- stream_key == "device_list_key"
269
+ stream_key == StreamKeyType . DEVICE_LIST
269
270
and not self ._msc3202_transaction_extensions_enabled
270
271
):
271
272
return
@@ -283,15 +284,15 @@ def notify_interested_services_ephemeral(
283
284
if (
284
285
stream_key
285
286
in (
286
- "typing_key" ,
287
- "receipt_key" ,
288
- "presence_key" ,
289
- "to_device_key" ,
287
+ StreamKeyType . TYPING ,
288
+ StreamKeyType . RECEIPT ,
289
+ StreamKeyType . PRESENCE ,
290
+ StreamKeyType . TO_DEVICE ,
290
291
)
291
292
and service .supports_ephemeral
292
293
)
293
294
or (
294
- stream_key == "device_list_key"
295
+ stream_key == StreamKeyType . DEVICE_LIST
295
296
and service .msc3202_transaction_extensions
296
297
)
297
298
]
@@ -317,7 +318,7 @@ async def _notify_interested_services_ephemeral(
317
318
logger .debug ("Checking interested services for %s" , stream_key )
318
319
with Measure (self .clock , "notify_interested_services_ephemeral" ):
319
320
for service in services :
320
- if stream_key == "typing_key" :
321
+ if stream_key == StreamKeyType . TYPING :
321
322
# Note that we don't persist the token (via set_appservice_stream_type_pos)
322
323
# for typing_key due to performance reasons and due to their highly
323
324
# ephemeral nature.
@@ -333,7 +334,7 @@ async def _notify_interested_services_ephemeral(
333
334
async with self ._ephemeral_events_linearizer .queue (
334
335
(service .id , stream_key )
335
336
):
336
- if stream_key == "receipt_key" :
337
+ if stream_key == StreamKeyType . RECEIPT :
337
338
events = await self ._handle_receipts (service , new_token )
338
339
self .scheduler .enqueue_for_appservice (service , ephemeral = events )
339
340
@@ -342,7 +343,7 @@ async def _notify_interested_services_ephemeral(
342
343
service , "read_receipt" , new_token
343
344
)
344
345
345
- elif stream_key == "presence_key" :
346
+ elif stream_key == StreamKeyType . PRESENCE :
346
347
events = await self ._handle_presence (service , users , new_token )
347
348
self .scheduler .enqueue_for_appservice (service , ephemeral = events )
348
349
@@ -351,7 +352,7 @@ async def _notify_interested_services_ephemeral(
351
352
service , "presence" , new_token
352
353
)
353
354
354
- elif stream_key == "to_device_key" :
355
+ elif stream_key == StreamKeyType . TO_DEVICE :
355
356
# Retrieve a list of to-device message events, as well as the
356
357
# maximum stream token of the messages we were able to retrieve.
357
358
to_device_messages = await self ._get_to_device_messages (
@@ -366,7 +367,7 @@ async def _notify_interested_services_ephemeral(
366
367
service , "to_device" , new_token
367
368
)
368
369
369
- elif stream_key == "device_list_key" :
370
+ elif stream_key == StreamKeyType . DEVICE_LIST :
370
371
device_list_summary = await self ._get_device_list_summary (
371
372
service , new_token
372
373
)
0 commit comments