summary refs log tree commit diff
path: root/synapse/storage/state.py
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2019-02-15 22:11:01 +0000
committerGitHub <noreply@github.com>2019-02-15 22:11:01 +0000
commitbd4505f765c1c17891dad390b18dc62b1b89e1a2 (patch)
tree2c478c31857d88c1452d6b8be75d017ef724957f /synapse/storage/state.py
parentMerge branch 'master' into develop (diff)
parentMove defaults up into code (diff)
downloadsynapse-bd4505f765c1c17891dad390b18dc62b1b89e1a2.tar.xz
Merge pull request #4647 from matrix-org/erikj/add_room_publishing_rules
Add configurable room list publishing rules
Diffstat (limited to 'synapse/storage/state.py')
-rw-r--r--synapse/storage/state.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index d14a7b2538..6ddc4055d2 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -548,6 +548,31 @@ class StateGroupWorkerStore(EventsWorkerStore, SQLBaseStore):
             _get_filtered_current_state_ids_txn,
         )
 
+    @defer.inlineCallbacks
+    def get_canonical_alias_for_room(self, room_id):
+        """Get canonical alias for room, if any
+
+        Args:
+            room_id (str)
+
+        Returns:
+            Deferred[str|None]: The canonical alias, if any
+        """
+
+        state = yield self.get_filtered_current_state_ids(room_id, StateFilter.from_types(
+            [(EventTypes.CanonicalAlias, "")]
+        ))
+
+        event_id = state.get((EventTypes.CanonicalAlias, ""))
+        if not event_id:
+            return
+
+        event = yield self.get_event(event_id, allow_none=True)
+        if not event:
+            return
+
+        defer.returnValue(event.content.get("canonical_alias"))
+
     @cached(max_entries=10000, iterable=True)
     def get_state_group_delta(self, state_group):
         """Given a state group try to return a previous group and a delta between