summary refs log tree commit diff
path: root/synapse/api
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-03-15 14:27:34 +0000
committerErik Johnston <erik@matrix.org>2017-03-15 14:27:34 +0000
commit6c82de51002575e974907ab0a7d4fc6b0123bc8f (patch)
tree7338a0d9c64ae83255404a7527bbdf90705a1a44 /synapse/api
parentMerge pull request #1997 from matrix-org/dbkr/cas_partialdownload (diff)
downloadsynapse-6c82de51002575e974907ab0a7d4fc6b0123bc8f.tar.xz
Format presence events on the edges instead of reformatting them multiple times
Diffstat (limited to 'synapse/api')
-rw-r--r--synapse/api/filtering.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py
index fb291d7fb9..63d5c75f43 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,30 @@ 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")
+        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 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")
+
+            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):