mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 17:13:50 +01:00
Add support for setting room name and topic when creating rooms
This commit is contained in:
parent
15a7312273
commit
040d985908
1 changed files with 29 additions and 4 deletions
|
@ -21,8 +21,8 @@ from synapse.api.constants import Membership, JoinRules
|
||||||
from synapse.api.errors import StoreError, SynapseError
|
from synapse.api.errors import StoreError, SynapseError
|
||||||
from synapse.api.events.room import (
|
from synapse.api.events.room import (
|
||||||
RoomMemberEvent, RoomCreateEvent, RoomPowerLevelsEvent,
|
RoomMemberEvent, RoomCreateEvent, RoomPowerLevelsEvent,
|
||||||
RoomJoinRulesEvent, RoomAddStateLevelEvent,
|
RoomJoinRulesEvent, RoomAddStateLevelEvent, RoomTopicEvent,
|
||||||
RoomSendEventLevelEvent, RoomOpsPowerLevelsEvent,
|
RoomSendEventLevelEvent, RoomOpsPowerLevelsEvent, RoomNameEvent,
|
||||||
)
|
)
|
||||||
from synapse.util import stringutils
|
from synapse.util import stringutils
|
||||||
from ._base import BaseRoomHandler
|
from ._base import BaseRoomHandler
|
||||||
|
@ -98,7 +98,6 @@ class RoomCreationHandler(BaseRoomHandler):
|
||||||
if not room_id:
|
if not room_id:
|
||||||
raise StoreError(500, "Couldn't generate a room ID.")
|
raise StoreError(500, "Couldn't generate a room ID.")
|
||||||
|
|
||||||
|
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
creation_events = self._create_events_for_new_room(
|
creation_events = self._create_events_for_new_room(
|
||||||
user, room_id, is_public=is_public
|
user, room_id, is_public=is_public
|
||||||
|
@ -113,7 +112,8 @@ class RoomCreationHandler(BaseRoomHandler):
|
||||||
|
|
||||||
federation_handler = self.hs.get_handlers().federation_handler
|
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(
|
snapshot = yield self.store.snapshot_room(
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
|
@ -124,6 +124,31 @@ class RoomCreationHandler(BaseRoomHandler):
|
||||||
yield self.state_handler.handle_new_event(event, snapshot)
|
yield self.state_handler.handle_new_event(event, snapshot)
|
||||||
yield self._on_new_room_event(event, snapshot, extra_users=[user])
|
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}
|
content = {"membership": Membership.JOIN}
|
||||||
join_event = self.event_factory.create_event(
|
join_event = self.event_factory.create_event(
|
||||||
etype=RoomMemberEvent.TYPE,
|
etype=RoomMemberEvent.TYPE,
|
||||||
|
|
Loading…
Reference in a new issue