|
69 | 69 | } |
70 | 70 |
|
71 | 71 |
|
| 72 | +SENTINEL = object() |
| 73 | + |
| 74 | + |
72 | 75 | def _should_count_as_unread(event: EventBase, context: EventContext) -> bool: |
73 | 76 | # Exclude rejected and soft-failed events. |
74 | 77 | if context.rejected or event.internal_metadata.is_soft_failed(): |
@@ -343,11 +346,21 @@ async def _action_for_event_by_user( |
343 | 346 | related_events = await self._related_events(event) |
344 | 347 |
|
345 | 348 | # It's possible that old room versions have non-integer power levels (floats or |
346 | | - # strings). Workaround this by explicitly converting to int. |
| 349 | + # strings; even the occasional `null`). For old rooms, we interpret these as if |
| 350 | + # they were integers. Do this here for the `@room` power level threshold. |
| 351 | + # Note that this is done automatically for the sender's power level by |
| 352 | + # _get_power_levels_and_sender_level in its call to get_user_power_level |
| 353 | + # (even for room V10.) |
347 | 354 | notification_levels = power_levels.get("notifications", {}) |
348 | 355 | if not event.room_version.msc3667_int_only_power_levels: |
349 | | - for user_id, level in notification_levels.items(): |
350 | | - notification_levels[user_id] = int(level) |
| 356 | + keys = list(notification_levels.keys()) |
| 357 | + for key in keys: |
| 358 | + level = notification_levels.get(key, SENTINEL) |
| 359 | + if level is not SENTINEL and type(level) is not int: |
| 360 | + try: |
| 361 | + notification_levels[key] = int(level) |
| 362 | + except (TypeError, ValueError): |
| 363 | + del notification_levels[key] |
351 | 364 |
|
352 | 365 | # Pull out any user and room mentions. |
353 | 366 | mentions = event.content.get(EventContentFields.MSC3952_MENTIONS) |
|
0 commit comments