summary refs log tree commit diff
path: root/synapse/storage/room.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-09-01 13:44:19 +0100
committerErik Johnston <erik@matrix.org>2014-09-01 14:39:09 +0100
commit865469f233aa37d3fa0de9a77dfb6bc597c569d7 (patch)
tree2bbd9037e0ac535369c0eb8485f8610ba28d700c /synapse/storage/room.py
parentMerge branch 'develop' of github.com:matrix-org/synapse into room_config (diff)
downloadsynapse-865469f233aa37d3fa0de9a77dfb6bc597c569d7.tar.xz
Implement power level lists, default power levels and send_evnet_level/add_state_level events.
Diffstat (limited to 'synapse/storage/room.py')
-rw-r--r--synapse/storage/room.py89
1 files changed, 72 insertions, 17 deletions
diff --git a/synapse/storage/room.py b/synapse/storage/room.py
index 8946ce99f7..f8aa8bd2a1 100644
--- a/synapse/storage/room.py
+++ b/synapse/storage/room.py
@@ -174,6 +174,28 @@ class RoomStore(SQLBaseStore):
         else:
             defer.returnValue(None)
 
+    def get_add_state_level(self, room_id):
+        return self._get_level_from_table("room_add_state_levels", room_id)
+
+    def get_send_event_level(self, room_id):
+        return self._get_level_from_table("room_send_event_levels", room_id)
+
+    @defer.inlineCallbacks
+    def _get_level_from_table(self, table, room_id):
+        sql = (
+            "SELECT level FROM %(table)s as r "
+            "INNER JOIN current_state_events as c "
+            "ON r.event_id = c.event_id "
+            "WHERE c.room_id = ? "
+        ) % {"table": table}
+
+        rows = yield self._execute(None, sql, room_id)
+
+        if len(rows) == 1:
+            defer.returnValue(rows[0][0])
+        else:
+            defer.returnValue(None)
+
     def _store_room_topic_txn(self, txn, event):
         self._simple_insert_txn(
             txn,
@@ -196,38 +218,71 @@ class RoomStore(SQLBaseStore):
             }
         )
 
-    def _store_join_rule(txn, event):
+    def _store_join_rule(self, txn, event):
         self._simple_insert_txn(
             txn,
             "room_join_rules",
             {
                 "event_id": event.event_id,
                 "room_id": event.room_id,
-                "join_rule": event.join_rule,
+                "join_rule": event.content["join_rule"],
             },
         )
 
-    def _store_power_levels(txn, event):
-        for user_id, level in event.content:
-            self._simple_insert_txn(
-                txn,
-                "room_power_levels",
-                {
-                    "event_id": event.event_id,
-                    "room_id": event.room_id,
-                    "user_id": user_id,
-                    "level": level
-                },
-            )
-
-    def _store_default_level(txn, event):
+    def _store_power_levels(self, txn, event):
+        for user_id, level in event.content.items():
+            if user_id == "default":
+                self._simple_insert_txn(
+                    txn,
+                    "room_default_levels",
+                    {
+                        "event_id": event.event_id,
+                        "room_id": event.room_id,
+                        "level": level,
+                    },
+                )
+            else:
+                self._simple_insert_txn(
+                    txn,
+                    "room_power_levels",
+                    {
+                        "event_id": event.event_id,
+                        "room_id": event.room_id,
+                        "user_id": user_id,
+                        "level": level
+                    },
+                )
+
+    def _store_default_level(self, txn, event):
         self._simple_insert_txn(
             txn,
             "room_default_levels",
             {
                 "event_id": event.event_id,
                 "room_id": event.room_id,
-                "level": level
+                "level": event.content["default_level"],
+            },
+        )
+
+    def _store_add_state_level(self, txn, event):
+        self._simple_insert_txn(
+            txn,
+            "room_add_state_levels",
+            {
+                "event_id": event.event_id,
+                "room_id": event.room_id,
+                "level": event.content["level"],
+            },
+        )
+
+    def _store_send_event_level(self, txn, event):
+        self._simple_insert_txn(
+            txn,
+            "room_send_event_levels",
+            {
+                "event_id": event.event_id,
+                "room_id": event.room_id,
+                "level": event.content["level"],
             },
         )