From a5b88c489ebf23e076a99306e7c95e9b60e83864 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 18 Nov 2014 15:03:01 +0000 Subject: Split out sending the room alias events from creating the alias so that we can do them in the right point when creating a room --- synapse/handlers/room.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'synapse/handlers/room.py') diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index cfe1061ed3..bfbd7f9783 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -106,6 +106,15 @@ class RoomCreationHandler(BaseHandler): if not room_id: raise StoreError(500, "Couldn't generate a room ID.") + if room_alias: + directory_handler = self.hs.get_handlers().directory_handler + yield directory_handler.create_association( + user_id=user_id, + room_id=room_id, + room_alias=room_alias, + servers=[self.hs.hostname], + ) + user = self.hs.parse_userid(user_id) creation_events = self._create_events_for_new_room( user, room_id, is_public=is_public @@ -180,13 +189,7 @@ class RoomCreationHandler(BaseHandler): if room_alias: result["room_alias"] = room_alias.to_string() - directory_handler = self.hs.get_handlers().directory_handler - yield directory_handler.create_association( - user_id=user_id, - room_id=room_id, - room_alias=room_alias, - servers=[self.hs.hostname], - ) + directory_handler.send_room_alias_update_event(user_id, room_id) defer.returnValue(result) -- cgit 1.4.1 From ae9c2ab1652511b36dc594882e88152b6067c816 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 18 Nov 2014 15:29:48 +0000 Subject: SYN-149: Send join event immediately after the room create event --- synapse/handlers/directory.py | 2 -- synapse/handlers/room.py | 50 ++++++++++++++++++++++--------------------- synapse/storage/directory.py | 5 +++++ 3 files changed, 31 insertions(+), 26 deletions(-) (limited to 'synapse/handlers/room.py') diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py index 5d79c6690c..98ac0684fc 100644 --- a/synapse/handlers/directory.py +++ b/synapse/handlers/directory.py @@ -21,8 +21,6 @@ from synapse.api.errors import SynapseError from synapse.api.events.room import RoomAliasesEvent import logging -import sqlite3 - logger = logging.getLogger(__name__) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index bfbd7f9783..4f47f5b6ae 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -120,15 +120,23 @@ class RoomCreationHandler(BaseHandler): user, room_id, is_public=is_public ) + room_member_handler = self.hs.get_handlers().room_member_handler + @defer.inlineCallbacks def handle_event(event): snapshot = yield self.store.snapshot_room(event) logger.debug("Event: %s", event) - yield self._on_new_room_event( - event, snapshot, extra_users=[user], suppress_auth=True - ) + if event.type == RoomMemberEvent.TYPE: + yield room_member_handler.change_membership( + event, + do_auth=False + ) + else: + yield self._on_new_room_event( + event, snapshot, extra_users=[user], suppress_auth=True + ) for event in creation_events: yield handle_event(event) @@ -155,16 +163,6 @@ class RoomCreationHandler(BaseHandler): yield handle_event(topic_event) - content = {"membership": Membership.JOIN} - join_event = self.event_factory.create_event( - etype=RoomMemberEvent.TYPE, - state_key=user_id, - room_id=room_id, - user_id=user_id, - membership=Membership.JOIN, - content=content - ) - content = {"membership": Membership.INVITE} for invitee in invite_list: invite_event = self.event_factory.create_event( @@ -174,16 +172,7 @@ class RoomCreationHandler(BaseHandler): user_id=user_id, content=content ) - - yield self.hs.get_handlers().room_member_handler.change_membership( - invite_event, - do_auth=False - ) - - yield self.hs.get_handlers().room_member_handler.change_membership( - join_event, - do_auth=False - ) + yield handle_event(invite_event) result = {"room_id": room_id} @@ -194,9 +183,11 @@ class RoomCreationHandler(BaseHandler): defer.returnValue(result) def _create_events_for_new_room(self, creator, room_id, is_public=False): + creator_id = creator.to_string() + event_keys = { "room_id": room_id, - "user_id": creator.to_string(), + "user_id": creator_id, } def create(etype, **content): @@ -211,6 +202,16 @@ class RoomCreationHandler(BaseHandler): creator=creator.to_string(), ) + join_event = self.event_factory.create_event( + etype=RoomMemberEvent.TYPE, + state_key=creator_id, + content={ + "membership": Membership.JOIN, + }, + **event_keys + ) + + power_levels_event = self.event_factory.create_event( etype=RoomPowerLevelsEvent.TYPE, content={ @@ -239,6 +240,7 @@ class RoomCreationHandler(BaseHandler): return [ creation_event, + join_event, power_levels_event, join_rules_event, ] diff --git a/synapse/storage/directory.py b/synapse/storage/directory.py index f2e895a5c2..2be9c41374 100644 --- a/synapse/storage/directory.py +++ b/synapse/storage/directory.py @@ -14,10 +14,15 @@ # limitations under the License. from ._base import SQLBaseStore + +from synapse.api.errors import SynapseError + from twisted.internet import defer from collections import namedtuple +import sqlite3 + RoomAliasMapping = namedtuple( "RoomAliasMapping", -- cgit 1.4.1 From b01dd76be105a90f1b5aa7083f43faf7b44693f3 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 18 Nov 2014 15:42:53 +0000 Subject: SYN-149: Enable auth for events added during room creation since they should pass auth checks --- synapse/handlers/room.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'synapse/handlers/room.py') diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 4f47f5b6ae..d09743ed1b 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -131,7 +131,7 @@ class RoomCreationHandler(BaseHandler): if event.type == RoomMemberEvent.TYPE: yield room_member_handler.change_membership( event, - do_auth=False + do_auth=True ) else: yield self._on_new_room_event( -- cgit 1.4.1