Support the backwards compatibility features in MSC3952. (#14958)

If the feature is enabled and the event has a `m.mentions` property,
skip processing of the legacy mentions rules.
This commit is contained in:
Patrick Cloke 2023-02-03 11:28:20 -05:00 committed by GitHub
parent 0a686d1d13
commit 52700a0bcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 190 additions and 65 deletions

View file

@ -119,6 +119,9 @@ class BulkPushRuleEvaluator:
self.should_calculate_push_rules = self.hs.config.push.enable_push
self._related_event_match_enabled = self.hs.config.experimental.msc3664_enabled
self._intentional_mentions_enabled = (
self.hs.config.experimental.msc3952_intentional_mentions
)
self.room_push_rule_cache_metrics = register_cache(
"cache",
@ -364,9 +367,12 @@ class BulkPushRuleEvaluator:
# Pull out any user and room mentions.
mentions = event.content.get(EventContentFields.MSC3952_MENTIONS)
has_mentions = self._intentional_mentions_enabled and isinstance(mentions, dict)
user_mentions: Set[str] = set()
room_mention = False
if isinstance(mentions, dict):
if has_mentions:
# mypy seems to have lost the type even though it must be a dict here.
assert isinstance(mentions, dict)
# Remove out any non-string items and convert to a set.
user_mentions_raw = mentions.get("user_ids")
if isinstance(user_mentions_raw, list):
@ -378,6 +384,7 @@ class BulkPushRuleEvaluator:
evaluator = PushRuleEvaluator(
_flatten_dict(event, room_version=event.room_version),
has_mentions,
user_mentions,
room_mention,
room_member_count,