mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-09-09 15:11:58 +00:00
Support filtering events represented as dicts.
This is useful because the emphemeral events such as presence and typing are represented as dicts inside synapse.
This commit is contained in:
parent
b0ac0a9438
commit
9b6f3bc742
@ -183,10 +183,29 @@ class Filter(object):
|
||||
Returns:
|
||||
bool: True if the event matches
|
||||
"""
|
||||
if isinstance(event, dict):
|
||||
return self.check_fields(
|
||||
event.get("room_id", None),
|
||||
event.get("sender", None),
|
||||
event.get("type", None),
|
||||
)
|
||||
else:
|
||||
return self.check_fields(
|
||||
event.room_id,
|
||||
event.sender,
|
||||
event.type,
|
||||
)
|
||||
|
||||
def check_fields(self, room_id, sender, event_type):
|
||||
"""Checks whether the filter matches the given event fields.
|
||||
|
||||
Returns:
|
||||
bool: True if the event fields match
|
||||
"""
|
||||
literal_keys = {
|
||||
"rooms": lambda v: event.room_id == v,
|
||||
"senders": lambda v: event.sender == v,
|
||||
"types": lambda v: _matches_wildcard(event.type, v)
|
||||
"rooms": lambda v: room_id == v,
|
||||
"senders": lambda v: sender == v,
|
||||
"types": lambda v: _matches_wildcard(event_type, v)
|
||||
}
|
||||
|
||||
for name, match_func in literal_keys.items():
|
||||
|
Loading…
Reference in New Issue
Block a user