-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Conversation
Add condition type to check the sender's power level and add a base rule using it for @channel notifications.
synapse/push/baserules.py
Outdated
{ | ||
'kind': 'event_match', | ||
'key': 'content.body', | ||
'pattern': '*@channel*', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's call it @room
) | ||
auth_events = yield self.store.get_events(auth_events_ids) | ||
auth_events = { | ||
(e.type, e.state_key): e for e in auth_events.values() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you want .itervalues()
here (which returns an iterator rather than constructing a new list)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably also move this in to the else, and explicitly do:
pl_event_key = (EventTypes.PowerLevels, "", )
pl_event_id = context.prev_state_ids.get((EventTypes.PowerLevels, "",))
if pl_event_id:
pl_event = yield self.store.get_event(pl_event_id)
auth_events = { pl_event_key: pl_event }
else:
...
defer.returnValue(get_user_power_level(event.sender, auth_events))
to avoid some allocations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it worth s/values/itervalues/ in the place I copied it from and all the other places that copied it from that too? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost certainly, so long as its obvious how its used
i'd avoid overcomplicating it with the layer of indirection to set a powerlevel for channel bing. if folks want that they can just surely add a custom push rule in the client (or in their particular server). conceptually this looks fine to me, but needs input from @erikjohnston on the state wrangling. |
@@ -109,6 +111,23 @@ def _get_rules_for_room(self, room_id): | |||
) | |||
|
|||
@defer.inlineCallbacks | |||
def _get_sender_power_level(self, event, context): | |||
pl_event_key = (EventTypes.PowerLevels, "", ) | |||
if pl_event_key in context.prev_state_ids: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's faster to do:
pl_event = context.prev_state_ids.get((EventTypes.PowerLevels, "",))
if pl_event:
...
synapse/push/push_rule_evaluator.py
Outdated
@@ -1,5 +1,6 @@ | |||
# -*- coding: utf-8 -*- | |||
# Copyright 2015, 2016 OpenMarket Ltd | |||
# Copyright 2015 New Vector Ltd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2015?
also update copyright
Rather than making the condition directly require a specific power level. This way the level require to notify a room can be configured per room.
Add condition type to check the sender's power level and add a base
rule using it for @channel notifications.
Thought: should we add a layer of indirection here so a channel can configure the minimum PL for sending a channel bing?