mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-22 11:24:57 -05:00
Implement specifying custom initial state for /createRoom
This commit is contained in:
parent
002a44ac1a
commit
c456d17daf
@ -27,6 +27,7 @@ from synapse.util import stringutils, unwrapFirstError
|
|||||||
from synapse.util.async import run_on_reactor
|
from synapse.util.async import run_on_reactor
|
||||||
from synapse.events.utils import serialize_event
|
from synapse.events.utils import serialize_event
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
import logging
|
import logging
|
||||||
import string
|
import string
|
||||||
|
|
||||||
@ -143,11 +144,18 @@ class RoomCreationHandler(BaseHandler):
|
|||||||
else RoomCreationPreset.PRIVATE_CHAT
|
else RoomCreationPreset.PRIVATE_CHAT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
raw_initial_state = config.get("initial_state", [])
|
||||||
|
|
||||||
|
initial_state = OrderedDict()
|
||||||
|
for val in raw_initial_state:
|
||||||
|
initial_state[(val["type"], val.get("state_key", ""))] = val["content"]
|
||||||
|
|
||||||
user = UserID.from_string(user_id)
|
user = UserID.from_string(user_id)
|
||||||
creation_events = self._create_events_for_new_room(
|
creation_events = self._create_events_for_new_room(
|
||||||
user, room_id,
|
user, room_id,
|
||||||
preset_config=preset_config,
|
preset_config=preset_config,
|
||||||
invite_list=invite_list,
|
invite_list=invite_list,
|
||||||
|
initial_state=initial_state,
|
||||||
)
|
)
|
||||||
|
|
||||||
msg_handler = self.hs.get_handlers().message_handler
|
msg_handler = self.hs.get_handlers().message_handler
|
||||||
@ -195,7 +203,7 @@ class RoomCreationHandler(BaseHandler):
|
|||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
|
|
||||||
def _create_events_for_new_room(self, creator, room_id, preset_config,
|
def _create_events_for_new_room(self, creator, room_id, preset_config,
|
||||||
invite_list):
|
invite_list, initial_state):
|
||||||
config = RoomCreationHandler.PRESETS_DICT[preset_config]
|
config = RoomCreationHandler.PRESETS_DICT[preset_config]
|
||||||
|
|
||||||
creator_id = creator.to_string()
|
creator_id = creator.to_string()
|
||||||
@ -230,6 +238,9 @@ class RoomCreationHandler(BaseHandler):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
returned_events = [creation_event, join_event]
|
||||||
|
|
||||||
|
if (EventTypes.PowerLevels, '') not in initial_state:
|
||||||
power_level_content = {
|
power_level_content = {
|
||||||
"users": {
|
"users": {
|
||||||
creator.to_string(): 100,
|
creator.to_string(): 100,
|
||||||
@ -257,23 +268,32 @@ class RoomCreationHandler(BaseHandler):
|
|||||||
content=power_level_content,
|
content=power_level_content,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
returned_events.append(power_levels_event)
|
||||||
|
|
||||||
|
if (EventTypes.JoinRules, '') not in initial_state:
|
||||||
join_rules_event = create(
|
join_rules_event = create(
|
||||||
etype=EventTypes.JoinRules,
|
etype=EventTypes.JoinRules,
|
||||||
content={"join_rule": config["join_rules"]},
|
content={"join_rule": config["join_rules"]},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
returned_events.append(join_rules_event)
|
||||||
|
|
||||||
|
if (EventTypes.RoomHistoryVisibility, '') not in initial_state:
|
||||||
history_event = create(
|
history_event = create(
|
||||||
etype=EventTypes.RoomHistoryVisibility,
|
etype=EventTypes.RoomHistoryVisibility,
|
||||||
content={"history_visibility": config["history_visibility"]}
|
content={"history_visibility": config["history_visibility"]}
|
||||||
)
|
)
|
||||||
|
|
||||||
return [
|
returned_events.append(history_event)
|
||||||
creation_event,
|
|
||||||
join_event,
|
for (etype, state_key), content in initial_state.items():
|
||||||
power_levels_event,
|
returned_events.append(create(
|
||||||
history_event,
|
etype=etype,
|
||||||
join_rules_event,
|
state_key=state_key,
|
||||||
]
|
content=content,
|
||||||
|
))
|
||||||
|
|
||||||
|
return returned_events
|
||||||
|
|
||||||
|
|
||||||
class RoomMemberHandler(BaseHandler):
|
class RoomMemberHandler(BaseHandler):
|
||||||
|
Loading…
Reference in New Issue
Block a user