summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-08-20 11:26:09 +0100
committerErik Johnston <erik@matrix.org>2015-08-20 11:26:09 +0100
commitcbd053bb8f0e5732f88a6ca3a9b8209ec41d7975 (patch)
treed36a52e67cdd805d45a7a90d5f546a4e819b99b8 /synapse
parentMerge pull request #234 from matrix-org/email_login (diff)
parentCheck that the canonical room alias actually points to the room (diff)
downloadsynapse-cbd053bb8f0e5732f88a6ca3a9b8209ec41d7975.tar.xz
Merge pull request #233 from matrix-org/erikj/canonical_alias
Add server side support for canonical aliases
Diffstat (limited to 'synapse')
-rw-r--r--synapse/api/constants.py1
-rw-r--r--synapse/handlers/_base.py18
-rw-r--r--synapse/handlers/room.py1
3 files changed, 19 insertions, 1 deletions
diff --git a/synapse/api/constants.py b/synapse/api/constants.py
index 7156ee4e7d..60a0d336da 100644
--- a/synapse/api/constants.py
+++ b/synapse/api/constants.py
@@ -76,6 +76,7 @@ class EventTypes(object):
     Feedback = "m.room.message.feedback"
 
     RoomHistoryVisibility = "m.room.history_visibility"
+    CanonicalAlias = "m.room.canonical_alias"
 
     # These are used for validation
     Message = "m.room.message"
diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py
index d6c064b398..e91f1129db 100644
--- a/synapse/handlers/_base.py
+++ b/synapse/handlers/_base.py
@@ -18,7 +18,7 @@ from twisted.internet import defer
 from synapse.api.errors import LimitExceededError, SynapseError
 from synapse.crypto.event_signing import add_hashes_and_signatures
 from synapse.api.constants import Membership, EventTypes
-from synapse.types import UserID
+from synapse.types import UserID, RoomAlias
 
 from synapse.util.logcontext import PreserveLoggingContext
 
@@ -130,6 +130,22 @@ class BaseHandler(object):
                         returned_invite.signatures
                     )
 
+        if event.type == EventTypes.CanonicalAlias:
+            # Check the alias is acually valid (at this time at least)
+            room_alias_str = event.content.get("alias", None)
+            if room_alias_str:
+                room_alias = RoomAlias.from_string(room_alias_str)
+                directory_handler = self.hs.get_handlers().directory_handler
+                mapping = yield directory_handler.get_association(room_alias)
+
+                if mapping["room_id"] != event.room_id:
+                    raise SynapseError(
+                        400,
+                        "Room alias %s does not point to the room" % (
+                            room_alias_str,
+                        )
+                    )
+
         destinations = set(extra_destinations)
         for k, s in context.current_state.items():
             try:
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index 82c16013a3..8108c2763d 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -250,6 +250,7 @@ class RoomCreationHandler(BaseHandler):
                     EventTypes.Name: 100,
                     EventTypes.PowerLevels: 100,
                     EventTypes.RoomHistoryVisibility: 100,
+                    EventTypes.CanonicalAlias: 100,
                 },
                 "events_default": 0,
                 "state_default": 50,