summary refs log tree commit diff
path: root/synapse/storage/room.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-08-29 15:18:30 +0100
committerErik Johnston <erik@matrix.org>2014-08-29 15:18:30 +0100
commit1118f02689032824122fd5d3f71c45811a70dd71 (patch)
tree12ce0c45d599f8f651a59db45489649d7fc11a91 /synapse/storage/room.py
parentMerge branch 'develop' of github.com:matrix-org/synapse into room_config (diff)
downloadsynapse-1118f02689032824122fd5d3f71c45811a70dd71.tar.xz
Start adding storage for new events.
Diffstat (limited to 'synapse/storage/room.py')
-rw-r--r--synapse/storage/room.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/synapse/storage/room.py b/synapse/storage/room.py
index d1f1a232f8..8946ce99f7 100644
--- a/synapse/storage/room.py
+++ b/synapse/storage/room.py
@@ -129,6 +129,51 @@ class RoomStore(SQLBaseStore):
 
         defer.returnValue(ret)
 
+    @defer.inlineCallbacks
+    def get_room_join_rule(self, room_id):
+        sql = (
+            "SELECT join_rule FROM room_join_rules as r "
+            "INNER JOIN current_state_events as c "
+            "ON r.event_id = c.event_id "
+            "WHERE c.room_id = ? "
+        )
+
+        rows = yield self._execute(None, sql, room_id)
+
+        if len(rows) == 1:
+            defer.returnValue(rows[0][0])
+        else:
+            defer.returnValue(None)
+
+    @defer.inlineCallbacks
+    def get_power_level(self, room_id, user_id):
+        sql = (
+            "SELECT level FROM room_power_levels as r "
+            "INNER JOIN current_state_events as c "
+            "ON r.event_id = c.event_id "
+            "WHERE c.room_id = ? AND r.user_id = ? "
+        )
+
+        rows = yield self._execute(None, sql, room_id, user_id)
+
+        if len(rows) == 1:
+            defer.returnValue(rows[0][0])
+            return
+
+        sql = (
+            "SELECT level FROM room_default_levels as r "
+            "INNER JOIN current_state_events as c "
+            "ON r.event_id = c.event_id "
+            "WHERE c.room_id = ? "
+        )
+
+        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,
@@ -151,6 +196,41 @@ class RoomStore(SQLBaseStore):
             }
         )
 
+    def _store_join_rule(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,
+            },
+        )
+
+    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):
+        self._simple_insert_txn(
+            txn,
+            "room_default_levels",
+            {
+                "event_id": event.event_id,
+                "room_id": event.room_id,
+                "level": level
+            },
+        )
+
 
 class RoomsTable(Table):
     table_name = "rooms"