Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit daf3a67

Browse files
gferonboxdot
andauthoredMay 31, 2023
Add get_canonical_room_alias to module API (#15450)
Co-authored-by: Boxdot <[email protected]>
1 parent c01343d commit daf3a67

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed
 

‎changelog.d/15450.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support resolving a room's [canonical alias](https://spec.matrix.org/v1.7/client-server-api/#mroomcanonical_alias) via the module API.

‎synapse/module_api/__init__.py

+27
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
JsonMapping,
123123
Requester,
124124
RoomAlias,
125+
RoomID,
125126
StateMap,
126127
UserID,
127128
UserInfo,
@@ -1570,6 +1571,32 @@ async def get_monthly_active_users_by_service(
15701571
start_timestamp, end_timestamp
15711572
)
15721573

1574+
async def get_canonical_room_alias(self, room_id: RoomID) -> Optional[RoomAlias]:
1575+
"""
1576+
Retrieve the given room's current canonical alias.
1577+
1578+
A room may declare an alias as "canonical", meaning that it is the
1579+
preferred alias to use when referring to the room. This function
1580+
retrieves that alias from the room's state.
1581+
1582+
Added in Synapse v1.86.0.
1583+
1584+
Args:
1585+
room_id: The Room ID to find the alias of.
1586+
1587+
Returns:
1588+
None if the room ID does not exist, or if the room exists but has no canonical alias.
1589+
Otherwise, the parsed room alias.
1590+
"""
1591+
room_alias_str = (
1592+
await self._storage_controllers.state.get_canonical_alias_for_room(
1593+
room_id.to_string()
1594+
)
1595+
)
1596+
if room_alias_str:
1597+
return RoomAlias.from_string(room_alias_str)
1598+
return None
1599+
15731600
async def lookup_room_alias(self, room_alias: str) -> Tuple[str, List[str]]:
15741601
"""
15751602
Get the room ID associated with a room alias.

‎synapse/storage/controllers/state.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ async def get_canonical_alias_for_room(self, room_id: str) -> Optional[str]:
485485
if not event:
486486
return None
487487

488-
return event.content.get("canonical_alias")
488+
return event.content.get("alias")
489489

490490
@trace
491491
@tag_args

0 commit comments

Comments
 (0)
This repository has been archived.