@@ -173,6 +173,89 @@ def test_create_room_then_modify_history_visibility(
173173 expect_code = HTTPStatus .FORBIDDEN ,
174174 )
175175
176+ def test_create_room_default_history_visibility_invited (self ) -> None :
177+ """
178+ Test that rooms are created with history visibility "invited" by default (A_25481),
179+ but users can override this setting during room creation
180+ """
181+ # Test 1: Private room created without explicit history_visibility should default to "invited"
182+ room_id_private = self .create_local_room (self .pro_user_a , [], is_public = False )
183+ assert room_id_private , "Private room should be created"
184+
185+ # Get the history visibility state event
186+ state_events = self .helper .get_state (
187+ room_id_private ,
188+ EventTypes .RoomHistoryVisibility ,
189+ tok = self .access_token_a ,
190+ )
191+ assert (
192+ state_events ["history_visibility" ] == HistoryVisibility .INVITED
193+ ), "Default history visibility should be 'invited'"
194+
195+ # Test 2: Public room created without explicit history_visibility should default to "invited"
196+ room_id_public = self .create_local_room (self .pro_user_a , [], is_public = True )
197+ assert room_id_public , "Public room should be created"
198+
199+ # Get the history visibility state event
200+ state_events = self .helper .get_state (
201+ room_id_public ,
202+ EventTypes .RoomHistoryVisibility ,
203+ tok = self .access_token_a ,
204+ )
205+ assert (
206+ state_events ["history_visibility" ] == HistoryVisibility .INVITED
207+ ), "Default history visibility should be 'invited'"
208+
209+ # Test 3: User can override history visibility during private room creation
210+ custom_history_visibility = {
211+ "type" : EventTypes .RoomHistoryVisibility ,
212+ "state_key" : "" ,
213+ "content" : {"history_visibility" : HistoryVisibility .SHARED },
214+ }
215+ override_content = {"initial_state" : [custom_history_visibility ]}
216+
217+ room_id_private_custom = self .create_local_room (
218+ self .pro_user_a , [], is_public = False , override_content = override_content
219+ )
220+ assert (
221+ room_id_private_custom
222+ ), "Private room with custom history visibility should be created"
223+
224+ # Get the history visibility state event for the custom room
225+ state_events_custom = self .helper .get_state (
226+ room_id_private_custom ,
227+ EventTypes .RoomHistoryVisibility ,
228+ tok = self .access_token_a ,
229+ )
230+ assert (
231+ state_events_custom ["history_visibility" ] == HistoryVisibility .SHARED
232+ ), "Custom history visibility should be respected"
233+
234+ # Test 4: User can override history visibility during public room creation
235+ custom_history_visibility = {
236+ "type" : EventTypes .RoomHistoryVisibility ,
237+ "state_key" : "" ,
238+ "content" : {"history_visibility" : HistoryVisibility .SHARED },
239+ }
240+ override_content = {"initial_state" : [custom_history_visibility ]}
241+
242+ room_id_public_custom = self .create_local_room (
243+ self .pro_user_a , [], is_public = True , override_content = override_content
244+ )
245+ assert (
246+ room_id_public_custom
247+ ), "Public room with custom history visibility should be created"
248+
249+ # Get the history visibility state event for the custom room
250+ state_events_custom = self .helper .get_state (
251+ room_id_public_custom ,
252+ EventTypes .RoomHistoryVisibility ,
253+ tok = self .access_token_a ,
254+ )
255+ assert (
256+ state_events_custom ["history_visibility" ] == HistoryVisibility .SHARED
257+ ), "Custom history visibility should be respected"
258+
176259
177260class LocalEpaModeCreateRoomTest (FederatingModuleApiTestCase ):
178261 """
@@ -323,3 +406,45 @@ def test_create_server_notices_room(self) -> None:
323406 # Retrieving the room_id is a sign that the room was created, the user was
324407 # invited, and the message was sent
325408 assert room_id , "Server notices room should have been found"
409+
410+ def test_create_room_default_history_visibility_invited (self ) -> None :
411+ """
412+ Test that rooms are created with history visibility "invited" by default (A_25481),
413+ but users can override this setting during room creation
414+ """
415+ # Test 1: Room created without explicit history_visibility should default to "invited"
416+ room_id = self .create_local_room (self .epa_user_d , [], is_public = False )
417+ assert room_id , "Room should be created"
418+
419+ # Get the history visibility state event
420+ state_events = self .helper .get_state (
421+ room_id ,
422+ EventTypes .RoomHistoryVisibility ,
423+ tok = self .access_token ,
424+ )
425+ assert (
426+ state_events ["history_visibility" ] == HistoryVisibility .INVITED
427+ ), "Default history visibility should be 'invited'"
428+
429+ # Test 2: User can override history visibility during room creation
430+ custom_history_visibility = {
431+ "type" : EventTypes .RoomHistoryVisibility ,
432+ "state_key" : "" ,
433+ "content" : {"history_visibility" : HistoryVisibility .SHARED },
434+ }
435+ override_content = {"initial_state" : [custom_history_visibility ]}
436+
437+ room_id_custom = self .create_local_room (
438+ self .epa_user_d , [], is_public = False , override_content = override_content
439+ )
440+ assert room_id_custom , "Room with custom history visibility should be created"
441+
442+ # Get the history visibility state event for the custom room
443+ state_events_custom = self .helper .get_state (
444+ room_id_custom ,
445+ EventTypes .RoomHistoryVisibility ,
446+ tok = self .access_token ,
447+ )
448+ assert (
449+ state_events_custom ["history_visibility" ] == HistoryVisibility .SHARED
450+ ), "Custom history visibility should be respected"
0 commit comments