Skip to content

Commit

Permalink
Add support for setting room name and topic when creating rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Sep 2, 2014
1 parent 15a7312 commit 040d985
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from synapse.api.errors import StoreError, SynapseError
from synapse.api.events.room import (
RoomMemberEvent, RoomCreateEvent, RoomPowerLevelsEvent,
RoomJoinRulesEvent, RoomAddStateLevelEvent,
RoomSendEventLevelEvent, RoomOpsPowerLevelsEvent,
RoomJoinRulesEvent, RoomAddStateLevelEvent, RoomTopicEvent,
RoomSendEventLevelEvent, RoomOpsPowerLevelsEvent, RoomNameEvent,
)
from synapse.util import stringutils
from ._base import BaseRoomHandler
Expand Down Expand Up @@ -98,7 +98,6 @@ def create_room(self, user_id, room_id, config):
if not room_id:
raise StoreError(500, "Couldn't generate a room ID.")


user = self.hs.parse_userid(user_id)
creation_events = self._create_events_for_new_room(
user, room_id, is_public=is_public
Expand All @@ -113,7 +112,8 @@ def create_room(self, user_id, room_id, config):

federation_handler = self.hs.get_handlers().federation_handler

for event in creation_events:
@defer.inlineCallbacks
def handle_event(event):
snapshot = yield self.store.snapshot_room(
room_id=room_id,
user_id=user_id,
Expand All @@ -124,6 +124,31 @@ def create_room(self, user_id, room_id, config):
yield self.state_handler.handle_new_event(event, snapshot)
yield self._on_new_room_event(event, snapshot, extra_users=[user])

for event in creation_events:
yield handle_event(event)

if "name" in config:
name = config["name"]
name_event = self.event_factory.create_event(
etype=RoomNameEvent.TYPE,
room_id=room_id,
user_id=user_id,
content={"name": name},
)

yield handle_event(name_event)

if "topic" in config:
topic = config["topic"]
topic_event = self.event_factory.create_event(
etype=RoomTopicEvent.TYPE,
room_id=room_id,
user_id=user_id,
content={"topic": topic},
)

yield handle_event(topic_event)

content = {"membership": Membership.JOIN}
join_event = self.event_factory.create_event(
etype=RoomMemberEvent.TYPE,
Expand Down

0 comments on commit 040d985

Please sign in to comment.