diff --git a/src/service.rs b/src/service.rs index b610f6fc..b9eee52b 100644 --- a/src/service.rs +++ b/src/service.rs @@ -61,7 +61,7 @@ impl Services { db, }, rooms: rooms::Service { - alias: db, + alias: rooms::alias::Service::new(db), auth_chain: rooms::auth_chain::Service { db, }, diff --git a/src/service/rooms/alias.rs b/src/service/rooms/alias.rs index 411199f4..3fc2d134 100644 --- a/src/service/rooms/alias.rs +++ b/src/service/rooms/alias.rs @@ -1,4 +1,52 @@ +use ruma::{OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId}; + +use crate::Result; + mod data; pub(crate) use data::Data; -pub(crate) type Service = &'static dyn Data; + +pub(crate) struct Service { + db: &'static dyn Data, +} + +impl Service { + pub(crate) fn new(db: &'static D) -> Self + where + D: Data, + { + Self { + db, + } + } + + /// Creates or updates the alias to the given room id. + pub(crate) fn set_alias( + &self, + alias: &RoomAliasId, + room_id: &RoomId, + ) -> Result<()> { + self.db.set_alias(alias, room_id) + } + + /// Forgets about an alias. Returns an error if the alias did not exist. + pub(crate) fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> { + self.db.remove_alias(alias) + } + + /// Looks up the roomid for the given alias. + pub(crate) fn resolve_local_alias( + &self, + alias: &RoomAliasId, + ) -> Result> { + self.db.resolve_local_alias(alias) + } + + /// Returns all local aliases that point to the given room + pub(crate) fn local_aliases_for_room<'a>( + &'a self, + room_id: &RoomId, + ) -> Box> + 'a> { + self.db.local_aliases_for_room(room_id) + } +}