summary refs log tree commit diff
path: root/synapse/storage/room.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-03-20 13:52:56 +0000
committerErik Johnston <erik@matrix.org>2015-03-20 13:52:56 +0000
commitcb8162d3d17a97574073d49bd6eef51c93b68157 (patch)
treec21af0524f31ce8ae069b0cd74c56ed27ed38868 /synapse/storage/room.py
parentGenerate transaction id in code (diff)
downloadsynapse-cb8162d3d17a97574073d49bd6eef51c93b68157.tar.xz
Rearrange storage modules
Diffstat (limited to 'synapse/storage/room.py')
-rw-r--r--synapse/storage/room.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/synapse/storage/room.py b/synapse/storage/room.py
index b5031f5c77..c64f8f53ac 100644
--- a/synapse/storage/room.py
+++ b/synapse/storage/room.py
@@ -161,6 +161,43 @@ class RoomStore(SQLBaseStore):
                 }
             )
 
+    @defer.inlineCallbacks
+    def get_room_name_and_aliases(self, room_id):
+        del_sql = (
+            "SELECT event_id FROM redactions WHERE redacts = e.event_id "
+            "LIMIT 1"
+        )
+
+        sql = (
+            "SELECT e.*, (%(redacted)s) AS redacted FROM events as e "
+            "INNER JOIN current_state_events as c ON e.event_id = c.event_id "
+            "INNER JOIN state_events as s ON e.event_id = s.event_id "
+            "WHERE c.room_id = ? "
+        ) % {
+            "redacted": del_sql,
+        }
+
+        sql += " AND ((s.type = 'm.room.name' AND s.state_key = '')"
+        sql += " OR s.type = 'm.room.aliases')"
+        args = (room_id,)
+
+        results = yield self._execute_and_decode("get_current_state", sql, *args)
+
+        events = yield self._parse_events(results)
+
+        name = None
+        aliases = []
+
+        for e in events:
+            if e.type == 'm.room.name':
+                if 'name' in e.content:
+                    name = e.content['name']
+            elif e.type == 'm.room.aliases':
+                if 'aliases' in e.content:
+                    aliases.extend(e.content['aliases'])
+
+        defer.returnValue((name, aliases))
+
 
 class RoomsTable(Table):
     table_name = "rooms"