@@ -569,7 +569,7 @@ async def clone_existing_room(
569
569
new_room_id ,
570
570
# we expect to override all the presets with initial_state, so this is
571
571
# somewhat arbitrary.
572
- preset_config = RoomCreationPreset .PRIVATE_CHAT ,
572
+ room_config = { "preset" : RoomCreationPreset .PRIVATE_CHAT } ,
573
573
invite_list = [],
574
574
initial_state = initial_state ,
575
575
creation_content = creation_content ,
@@ -904,13 +904,6 @@ async def create_room(
904
904
check_membership = False ,
905
905
)
906
906
907
- preset_config = config .get (
908
- "preset" ,
909
- RoomCreationPreset .PRIVATE_CHAT
910
- if visibility == "private"
911
- else RoomCreationPreset .PUBLIC_CHAT ,
912
- )
913
-
914
907
raw_initial_state = config .get ("initial_state" , [])
915
908
916
909
initial_state = OrderedDict ()
@@ -929,7 +922,7 @@ async def create_room(
929
922
) = await self ._send_events_for_new_room (
930
923
requester ,
931
924
room_id ,
932
- preset_config = preset_config ,
925
+ room_config = config ,
933
926
invite_list = invite_list ,
934
927
initial_state = initial_state ,
935
928
creation_content = creation_content ,
@@ -938,48 +931,6 @@ async def create_room(
938
931
creator_join_profile = creator_join_profile ,
939
932
)
940
933
941
- if "name" in config :
942
- name = config ["name" ]
943
- (
944
- name_event ,
945
- last_stream_id ,
946
- ) = await self .event_creation_handler .create_and_send_nonmember_event (
947
- requester ,
948
- {
949
- "type" : EventTypes .Name ,
950
- "room_id" : room_id ,
951
- "sender" : user_id ,
952
- "state_key" : "" ,
953
- "content" : {"name" : name },
954
- },
955
- ratelimit = False ,
956
- prev_event_ids = [last_sent_event_id ],
957
- depth = depth ,
958
- )
959
- last_sent_event_id = name_event .event_id
960
- depth += 1
961
-
962
- if "topic" in config :
963
- topic = config ["topic" ]
964
- (
965
- topic_event ,
966
- last_stream_id ,
967
- ) = await self .event_creation_handler .create_and_send_nonmember_event (
968
- requester ,
969
- {
970
- "type" : EventTypes .Topic ,
971
- "room_id" : room_id ,
972
- "sender" : user_id ,
973
- "state_key" : "" ,
974
- "content" : {"topic" : topic },
975
- },
976
- ratelimit = False ,
977
- prev_event_ids = [last_sent_event_id ],
978
- depth = depth ,
979
- )
980
- last_sent_event_id = topic_event .event_id
981
- depth += 1
982
-
983
934
# we avoid dropping the lock between invites, as otherwise joins can
984
935
# start coming in and making the createRoom slow.
985
936
#
@@ -1047,7 +998,7 @@ async def _send_events_for_new_room(
1047
998
self ,
1048
999
creator : Requester ,
1049
1000
room_id : str ,
1050
- preset_config : str ,
1001
+ room_config : JsonDict ,
1051
1002
invite_list : List [str ],
1052
1003
initial_state : MutableStateMap ,
1053
1004
creation_content : JsonDict ,
@@ -1064,11 +1015,33 @@ async def _send_events_for_new_room(
1064
1015
1065
1016
Rate limiting should already have been applied by this point.
1066
1017
1018
+ Args:
1019
+ creator:
1020
+ the user requesting the room creation
1021
+ room_id:
1022
+ room id for the room being created
1023
+ room_config:
1024
+ A dict of configuration options. This will be the body of
1025
+ a /createRoom request; see
1026
+ https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3createroom
1027
+ invite_list:
1028
+ a list of user ids to invite to the room
1029
+ initial_state:
1030
+ A list of state events to set in the new room.
1031
+ creation_content:
1032
+ Extra keys, such as m.federate, to be added to the content of the m.room.create event.
1033
+ room_alias:
1034
+ alias for the room
1035
+ power_level_content_override:
1036
+ The power level content to override in the default power level event.
1037
+ creator_join_profile:
1038
+ Set to override the displayname and avatar for the creating
1039
+ user in this room.
1040
+
1067
1041
Returns:
1068
1042
A tuple containing the stream ID, event ID and depth of the last
1069
1043
event sent to the room.
1070
1044
"""
1071
-
1072
1045
creator_id = creator .user .to_string ()
1073
1046
event_keys = {"room_id" : room_id , "sender" : creator_id , "state_key" : "" }
1074
1047
depth = 1
@@ -1079,9 +1052,6 @@ async def _send_events_for_new_room(
1079
1052
# created (but not persisted to the db) to determine state for future created events
1080
1053
# (as this info can't be pulled from the db)
1081
1054
state_map : MutableStateMap [str ] = {}
1082
- # current_state_group of last event created. Used for computing event context of
1083
- # events to be batched
1084
- current_state_group : Optional [int ] = None
1085
1055
1086
1056
def create_event_dict (etype : str , content : JsonDict , ** kwargs : Any ) -> JsonDict :
1087
1057
e = {"type" : etype , "content" : content }
@@ -1135,6 +1105,14 @@ async def create_event(
1135
1105
1136
1106
return new_event , new_unpersisted_context
1137
1107
1108
+ visibility = room_config .get ("visibility" , "private" )
1109
+ preset_config = room_config .get (
1110
+ "preset" ,
1111
+ RoomCreationPreset .PRIVATE_CHAT
1112
+ if visibility == "private"
1113
+ else RoomCreationPreset .PUBLIC_CHAT ,
1114
+ )
1115
+
1138
1116
try :
1139
1117
config = self ._presets_dict [preset_config ]
1140
1118
except KeyError :
@@ -1286,6 +1264,24 @@ async def create_event(
1286
1264
)
1287
1265
events_to_send .append ((encryption_event , encryption_context ))
1288
1266
1267
+ if "name" in room_config :
1268
+ name = room_config ["name" ]
1269
+ name_event , name_context = await create_event (
1270
+ EventTypes .Name ,
1271
+ {"name" : name },
1272
+ True ,
1273
+ )
1274
+ events_to_send .append ((name_event , name_context ))
1275
+
1276
+ if "topic" in room_config :
1277
+ topic = room_config ["topic" ]
1278
+ topic_event , topic_context = await create_event (
1279
+ EventTypes .Topic ,
1280
+ {"topic" : topic },
1281
+ True ,
1282
+ )
1283
+ events_to_send .append ((topic_event , topic_context ))
1284
+
1289
1285
datastore = self .hs .get_datastores ().state
1290
1286
events_and_context = (
1291
1287
await UnpersistedEventContext .batch_persist_unpersisted_contexts (
0 commit comments