diff options
author | Erik Johnston <erikj@jki.re> | 2017-03-15 16:01:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-15 16:01:29 +0000 |
commit | 9d527191bcd14f51ae43cfccf18a34ecb19df801 (patch) | |
tree | 272a697640aaf3c919db0b63967908e89b8f16f5 /synapse/api | |
parent | Merge pull request #1997 from matrix-org/dbkr/cas_partialdownload (diff) | |
parent | Comment (diff) | |
download | synapse-9d527191bcd14f51ae43cfccf18a34ecb19df801.tar.xz |
Merge pull request #2013 from matrix-org/erikj/presence_FASTER
Format presence events on the edges instead of reformatting them multiple times
Diffstat (limited to 'synapse/api')
-rw-r--r-- | synapse/api/filtering.py | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py index fb291d7fb9..47f0cf0fa9 100644 --- a/synapse/api/filtering.py +++ b/synapse/api/filtering.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from synapse.api.errors import SynapseError +from synapse.storage.presence import UserPresenceState from synapse.types import UserID, RoomID from twisted.internet import defer @@ -253,19 +254,35 @@ class Filter(object): Returns: bool: True if the event matches """ - sender = event.get("sender", None) - if not sender: - # Presence events have their 'sender' in content.user_id - content = event.get("content") - # account_data has been allowed to have non-dict content, so check type first - if isinstance(content, dict): - sender = content.get("user_id") + # We usually get the full "events" as dictionaries coming through, + # except for presence which actually gets passed around as its own + # namedtuple type. + if isinstance(event, UserPresenceState): + sender = event.user_id + room_id = None + ev_type = "m.presence" + is_url = False + else: + sender = event.get("sender", None) + if not sender: + # Presence events had their 'sender' in content.user_id, but are + # now handled above. We don't know if anything else uses this + # form. TODO: Check this and probably remove it. + content = event.get("content") + # account_data has been allowed to have non-dict content, so + # check type first + if isinstance(content, dict): + sender = content.get("user_id") + + room_id = event.get("room_id", None) + ev_type = event.get("type", None) + is_url = "url" in event.get("content", {}) return self.check_fields( - event.get("room_id", None), + room_id, sender, - event.get("type", None), - "url" in event.get("content", {}) + ev_type, + is_url, ) def check_fields(self, room_id, sender, event_type, contains_url): |