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

Commit e194241

Browse files
author
David Robertson
committed
Handle None values in notifications.room
1 parent 37971fa commit e194241

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

synapse/push/bulk_push_rule_evaluator.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
}
7070

7171

72+
SENTINEL = object()
73+
74+
7275
def _should_count_as_unread(event: EventBase, context: EventContext) -> bool:
7376
# Exclude rejected and soft-failed events.
7477
if context.rejected or event.internal_metadata.is_soft_failed():
@@ -343,11 +346,21 @@ async def _action_for_event_by_user(
343346
related_events = await self._related_events(event)
344347

345348
# 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.)
347354
notification_levels = power_levels.get("notifications", {})
348355
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]
351364

352365
# Pull out any user and room mentions.
353366
mentions = event.content.get(EventContentFields.MSC3952_MENTIONS)

0 commit comments

Comments
 (0)