File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ Add a module API method to translate a room alias into a room ID.
Original file line number Diff line number Diff line change @@ -1452,6 +1452,30 @@ async def get_monthly_active_users_by_service(
1452
1452
start_timestamp , end_timestamp
1453
1453
)
1454
1454
1455
+ async def lookup_room_alias (self , room_alias : str ) -> Tuple [str , List [str ]]:
1456
+ """
1457
+ Get the room ID associated with a room alias.
1458
+
1459
+ Added in Synapse v1.65.0.
1460
+
1461
+ Args:
1462
+ room_alias: The alias to look up.
1463
+
1464
+ Returns:
1465
+ A tuple of:
1466
+ The room ID (str).
1467
+ Hosts likely to be participating in the room ([str]).
1468
+
1469
+ Raises:
1470
+ SynapseError if room alias is invalid or could not be found.
1471
+ """
1472
+ alias = RoomAlias .from_string (room_alias )
1473
+ (room_id , hosts ) = await self ._hs .get_room_member_handler ().lookup_room_alias (
1474
+ alias
1475
+ )
1476
+
1477
+ return room_id .to_string (), hosts
1478
+
1455
1479
1456
1480
class PublicRoomListManager :
1457
1481
"""Contains methods for adding to, removing from and querying whether a room
Original file line number Diff line number Diff line change @@ -635,6 +635,25 @@ def test_check_push_rules_actions(self) -> None:
635
635
[{"set_tweak" : "sound" , "value" : "default" }]
636
636
)
637
637
638
+ def test_lookup_room_alias (self ) -> None :
639
+ """Test that modules can resolve a room alias to a room ID."""
640
+ password = "password"
641
+ user_id = self .register_user ("user" , password )
642
+ access_token = self .login (user_id , password )
643
+ room_alias = "my-alias"
644
+ reference_room_id = self .helper .create_room_as (
645
+ tok = access_token , extra_content = {"room_alias_name" : room_alias }
646
+ )
647
+ self .assertIsNotNone (reference_room_id )
648
+
649
+ (room_id , _ ) = self .get_success (
650
+ self .module_api .lookup_room_alias (
651
+ f"#{ room_alias } :{ self .module_api .server_name } "
652
+ )
653
+ )
654
+
655
+ self .assertEqual (room_id , reference_room_id )
656
+
638
657
639
658
class ModuleApiWorkerTestCase (BaseMultiWorkerStreamTestCase ):
640
659
"""For testing ModuleApi functionality in a multi-worker setup"""
You can’t perform that action at this time.
0 commit comments