From f127987c7a34a318b92dfbe7433fcfaa496173a2 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 23 Jun 2024 02:57:32 +0000 Subject: [PATCH] add convenience alias resolver to interface Signed-off-by: Jason Volk --- src/service/rooms/alias/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/service/rooms/alias/mod.rs b/src/service/rooms/alias/mod.rs index 6397ef7f..9f66cf88 100644 --- a/src/service/rooms/alias/mod.rs +++ b/src/service/rooms/alias/mod.rs @@ -12,7 +12,7 @@ use ruma::{ room::power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent}, StateEventType, }, - OwnedRoomAliasId, OwnedRoomId, OwnedServerName, RoomAliasId, RoomId, UserId, + OwnedRoomAliasId, OwnedRoomId, OwnedServerName, RoomAliasId, RoomId, RoomOrAliasId, UserId, }; use crate::{appservice::RegistrationInfo, server_is_ours, services}; @@ -52,6 +52,16 @@ impl Service { } } + pub async fn resolve(&self, room: &RoomOrAliasId) -> Result { + if room.is_room_id() { + let room_id: &RoomId = &RoomId::parse(room).expect("valid RoomId"); + Ok(room_id.to_owned()) + } else { + let alias: &RoomAliasId = &RoomAliasId::parse(room).expect("valid RoomAliasId"); + Ok(self.resolve_alias(alias, None).await?.0) + } + } + #[tracing::instrument(skip(self), name = "resolve")] pub async fn resolve_alias( &self, room_alias: &RoomAliasId, servers: Option<&Vec>,