summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-07-08 11:36:05 +0100
committerErik Johnston <erik@matrix.org>2015-07-08 11:36:05 +0100
commitd85ce8d89bc1fb6ff6f277fb424dddca7ab2f47e (patch)
treef617680c3bcfbedae08691a2de6b0e66d7ad72a1
parentHook up receipts to v1 initialSync (diff)
downloadsynapse-d85ce8d89bc1fb6ff6f277fb424dddca7ab2f47e.tar.xz
Split receipt events up into one per room
-rw-r--r--synapse/handlers/receipts.py51
1 files changed, 21 insertions, 30 deletions
diff --git a/synapse/handlers/receipts.py b/synapse/handlers/receipts.py
index f6cde30e63..b7567b9ead 100644
--- a/synapse/handlers/receipts.py
+++ b/synapse/handlers/receipts.py
@@ -144,9 +144,8 @@ class ReceiptsHandler(BaseHandler):
 
         event = {
             "type": "m.receipt",
-            "content": {
-                room_id: result,
-            },
+            "room_id": room_id,
+            "content": result,
         }
 
         defer.returnValue([event])
@@ -163,23 +162,19 @@ class ReceiptEventSource(object):
 
         rooms = yield self.store.get_rooms_for_user(user.to_string())
         rooms = [room.room_id for room in rooms]
-        content = {}
+        events = []
         for room_id in rooms:
-            result = yield self.store.get_linearized_receipts_for_room(
+            content = yield self.store.get_linearized_receipts_for_room(
                 room_id, from_key, to_key
             )
-            if result:
-                content[room_id] = result
-
-        if not content:
-            defer.returnValue(([], to_key))
-
-        event = {
-            "type": "m.receipt",
-            "content": content,
-        }
+            if content:
+                events.append({
+                    "type": "m.receipt",
+                    "room_id": room_id,
+                    "content": content,
+                })
 
-        defer.returnValue(([event], to_key))
+        defer.returnValue((events, to_key))
 
     def get_current_key(self, direction='f'):
         return self.store.get_max_receipt_stream_id()
@@ -195,20 +190,16 @@ class ReceiptEventSource(object):
 
         rooms = yield self.store.get_rooms_for_user(user.to_string())
         rooms = [room.room_id for room in rooms]
-        content = {}
+        events = []
         for room_id in rooms:
-            result = yield self.store.get_linearized_receipts_for_room(
+            content = yield self.store.get_linearized_receipts_for_room(
                 room_id, from_key, to_key
             )
-            if result:
-                content[room_id] = result
-
-        if not content:
-            defer.returnValue(([], to_key))
-
-        event = {
-            "type": "m.receipt",
-            "content": content,
-        }
-
-        defer.returnValue(([event], to_key))
+            if content:
+                events.append({
+                    "type": "m.receipt",
+                    "room_id": room_id,
+                    "content": content,
+                })
+
+        defer.returnValue((events, to_key))