add convenience alias resolver to interface

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-06-23 02:57:32 +00:00
parent fa02d7b7e3
commit f127987c7a

View file

@ -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<OwnedRoomId> {
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<OwnedServerName>>,