summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/__init__.py12
-rw-r--r--synapse/storage/roommember.py22
2 files changed, 26 insertions, 8 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index 8c2c82c1bb..514d7eeb69 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -94,11 +94,11 @@ class DataStore(RoomMemberStore, RoomStore,
     def _persist_pdu_event_txn(self, txn, pdu=None, event=None,
                                backfilled=False, stream_ordering=None):
         if pdu is not None:
-            self._persist_pdu_txn(txn, pdu)
+            self._persist_event_pdu_txn(txn, pdu)
         if event is not None:
             self._persist_event_txn(txn, event, backfilled, stream_ordering)
 
-    def _persist_pdu_txn(self, txn, pdu):
+    def _persist_event_pdu_txn(self, txn, pdu):
         cols = dict(pdu.__dict__)
         unrec_keys = dict(pdu.unrecognized_keys)
         del cols["content"]
@@ -185,7 +185,7 @@ class DataStore(RoomMemberStore, RoomStore,
                 }
             )
 
-        return self._get_room_events_max_id_(txn)
+        return self._get_room_events_max_id_txn(txn)
 
     @defer.inlineCallbacks
     def get_current_state(self, room_id, event_type=None, state_key=""):
@@ -232,7 +232,7 @@ class DataStore(RoomMemberStore, RoomStore,
             synapse.storage.Snapshot: A snapshot of the state of the room.
         """
         def _snapshot(txn):
-            membership_state = self._get_room_member(txn, user_id)
+            membership_state = self._get_room_member(txn, user_id, room_id)
             prev_pdus = self._get_latest_pdus_in_context(
                 txn, room_id
             )
@@ -279,7 +279,7 @@ class Snapshot(object):
         self.room_id = room_id
         self.user_id = user_id
         self.prev_pdus = prev_pdus
-        self.membership_state
+        self.membership_state = membership_state
         self.state_type = state_type
         self.state_key = state_key
         self.prev_state_pdu = prev_state_pdu
@@ -295,7 +295,7 @@ class Snapshot(object):
         event.prev_events = [e for e in es if e != event.event_id]
 
         if self.prev_pdus:
-            event.depth = max([int(v) for _, _, v in results]) + 1
+            event.depth = max([int(v) for _, _, v in self.prev_pdus]) + 1
         else:
             event.depth = 0
 
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index 5038aeea03..2746126e85 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -50,13 +50,13 @@ class RoomMemberStore(SQLBaseStore):
                 "INSERT OR IGNORE INTO room_hosts (room_id, host) "
                 "VALUES (?, ?)"
             )
-            txn.execute(sql, event.room_id, domain)
+            txn.execute(sql, (event.room_id, domain))
         else:
             sql = (
                 "DELETE FROM room_hosts WHERE room_id = ? AND host = ?"
             )
 
-            txn.execute(sql, event.room_id, domain)
+            txn.execute(sql, (event.room_id, domain))
 
     @defer.inlineCallbacks
     def get_room_member(self, user_id, room_id):
@@ -75,6 +75,24 @@ class RoomMemberStore(SQLBaseStore):
 
         defer.returnValue(rows[0] if rows else None)
 
+    def _get_room_member(self, txn, user_id, room_id):
+        sql = (
+            "SELECT e.* FROM events as e"
+            " INNER JOIN room_memberships as m"
+            " ON e.event_id = m.event_id"
+            " INNER JOIN current_state_events as c"
+            " ON m.event_id = c.event_id"
+            " WHERE m.user_id = ? and e.room_id = ?"
+            " LIMIT 1"
+        )
+        txn.execute(sql, (user_id, room_id))
+        rows = self.cursor_to_dict(txn)
+        if rows:
+            return self._parse_event_from_row(rows[0])
+        else:
+            return None
+
+
     def get_room_members(self, room_id, membership=None):
         """Retrieve the current room member list for a room.