diff options
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/__init__.py | 2 | ||||
-rw-r--r-- | synapse/storage/room.py | 57 | ||||
-rw-r--r-- | synapse/storage/schema/im.sql | 11 |
3 files changed, 63 insertions, 7 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py index 3d5e5049fa..cc8b59f8da 100644 --- a/synapse/storage/__init__.py +++ b/synapse/storage/__init__.py @@ -127,8 +127,6 @@ class DataStore(RoomMemberStore, RoomStore, self._store_room_member_txn(txn, event) elif event.type == FeedbackEvent.TYPE: self._store_feedback_txn(txn, event) -# elif event.type == RoomConfigEvent.TYPE: -# self._store_room_config_txn(txn, event) elif event.type == RoomNameEvent.TYPE: self._store_room_name_txn(txn, event) elif event.type == RoomTopicEvent.TYPE: diff --git a/synapse/storage/room.py b/synapse/storage/room.py index f8aa8bd2a1..3b2d1a8ecd 100644 --- a/synapse/storage/room.py +++ b/synapse/storage/room.py @@ -27,6 +27,9 @@ import logging logger = logging.getLogger(__name__) +OpsLevel = collections.namedtuple("OpsLevel", ("ban_level", "kick_level")) + + class RoomStore(SQLBaseStore): @defer.inlineCallbacks @@ -145,8 +148,13 @@ class RoomStore(SQLBaseStore): else: defer.returnValue(None) - @defer.inlineCallbacks def get_power_level(self, room_id, user_id): + return self._db_pool.runInteraction( + self._get_power_level, + room_id, user_id, + ) + + def _get_power_level(self, txn, room_id, user_id): sql = ( "SELECT level FROM room_power_levels as r " "INNER JOIN current_state_events as c " @@ -154,7 +162,7 @@ class RoomStore(SQLBaseStore): "WHERE c.room_id = ? AND r.user_id = ? " ) - rows = yield self._execute(None, sql, room_id, user_id) + rows = txn.execute(sql, (room_id, user_id,)).fetchall() if len(rows) == 1: defer.returnValue(rows[0][0]) @@ -167,12 +175,33 @@ class RoomStore(SQLBaseStore): "WHERE c.room_id = ? " ) - rows = yield self._execute(None, sql, room_id) + rows = txn.execute(sql, (room_id,)).fetchall() if len(rows) == 1: - defer.returnValue(rows[0][0]) + return rows[0][0] else: - defer.returnValue(None) + return None + + def get_ops_levels(self, room_id): + return self._db_pool.runInteraction( + self._get_ops_levels, + room_id, + ) + + def _get_ops_levels(self, txn, room_id): + sql = ( + "SELECT ban_level, kick_level FROM room_ops_levels as r " + "INNER JOIN current_state_events as c " + "ON r.event_id = c.event_id " + "WHERE c.room_id = ? " + ) + + rows = txn.execute(sql, (room_id,)).fetchall() + + if len(rows) == 1: + return OpsLevel(rows[0][0], rows[0][1]) + else: + return OpsLevel(None, None) def get_add_state_level(self, room_id): return self._get_level_from_table("room_add_state_levels", room_id) @@ -286,6 +315,24 @@ class RoomStore(SQLBaseStore): }, ) + def _store_ops_level(self, txn, event): + content = { + "event_id": event.event_id, + "room_id": event.room_id, + } + + if "kick_level" in event.content: + content["kick_level"] = event.content["kick_level"] + + if "ban_level" in event.content: + content["ban_level"] = event.content["ban_level"] + + self._simple_insert_txn( + txn, + "room_send_event_levels", + content, + ) + class RoomsTable(Table): table_name = "rooms" diff --git a/synapse/storage/schema/im.sql b/synapse/storage/schema/im.sql index 447c1d29a2..1de0d59066 100644 --- a/synapse/storage/schema/im.sql +++ b/synapse/storage/schema/im.sql @@ -146,6 +146,17 @@ CREATE INDEX IF NOT EXISTS room_send_event_levels_event_id ON room_send_event_le CREATE INDEX IF NOT EXISTS room_send_event_levels_room_id ON room_send_event_levels(room_id); +CREATE TABLE IF NOT EXISTS room_ops_levels( + event_id TEXT NOT NULL, + room_id TEXT NOT NULL, + ban_level INTEGER, + kick_level INTEGER, +); + +CREATE INDEX IF NOT EXISTS room_ops_levels_event_id ON room_ops_levels(event_id); +CREATE INDEX IF NOT EXISTS room_ops_levels_room_id ON room_ops_levels(room_id); + + CREATE TABLE IF NOT EXISTS room_hosts( room_id TEXT NOT NULL, host TEXT NOT NULL, |