mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 22:33:50 +01:00
Add get_canonical_room_alias to module API (#15450)
Co-authored-by: Boxdot <d@zerovolt.org>
This commit is contained in:
parent
c01343de43
commit
daf3a67908
3 changed files with 29 additions and 1 deletions
1
changelog.d/15450.feature
Normal file
1
changelog.d/15450.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Support resolving a room's [canonical alias](https://spec.matrix.org/v1.7/client-server-api/#mroomcanonical_alias) via the module API.
|
|
@ -122,6 +122,7 @@ from synapse.types import (
|
||||||
JsonMapping,
|
JsonMapping,
|
||||||
Requester,
|
Requester,
|
||||||
RoomAlias,
|
RoomAlias,
|
||||||
|
RoomID,
|
||||||
StateMap,
|
StateMap,
|
||||||
UserID,
|
UserID,
|
||||||
UserInfo,
|
UserInfo,
|
||||||
|
@ -1570,6 +1571,32 @@ class ModuleApi:
|
||||||
start_timestamp, end_timestamp
|
start_timestamp, end_timestamp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def get_canonical_room_alias(self, room_id: RoomID) -> Optional[RoomAlias]:
|
||||||
|
"""
|
||||||
|
Retrieve the given room's current canonical alias.
|
||||||
|
|
||||||
|
A room may declare an alias as "canonical", meaning that it is the
|
||||||
|
preferred alias to use when referring to the room. This function
|
||||||
|
retrieves that alias from the room's state.
|
||||||
|
|
||||||
|
Added in Synapse v1.86.0.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
room_id: The Room ID to find the alias of.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None if the room ID does not exist, or if the room exists but has no canonical alias.
|
||||||
|
Otherwise, the parsed room alias.
|
||||||
|
"""
|
||||||
|
room_alias_str = (
|
||||||
|
await self._storage_controllers.state.get_canonical_alias_for_room(
|
||||||
|
room_id.to_string()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if room_alias_str:
|
||||||
|
return RoomAlias.from_string(room_alias_str)
|
||||||
|
return None
|
||||||
|
|
||||||
async def lookup_room_alias(self, room_alias: str) -> Tuple[str, List[str]]:
|
async def lookup_room_alias(self, room_alias: str) -> Tuple[str, List[str]]:
|
||||||
"""
|
"""
|
||||||
Get the room ID associated with a room alias.
|
Get the room ID associated with a room alias.
|
||||||
|
|
|
@ -485,7 +485,7 @@ class StateStorageController:
|
||||||
if not event:
|
if not event:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return event.content.get("canonical_alias")
|
return event.content.get("alias")
|
||||||
|
|
||||||
@trace
|
@trace
|
||||||
@tag_args
|
@tag_args
|
||||||
|
|
Loading…
Reference in a new issue