reintroduce rooms::alias::Serivce struct

We're going to need it.
This commit is contained in:
Charles Hall 2024-06-12 16:41:52 -07:00
parent 339a869872
commit 273ab33809
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
2 changed files with 50 additions and 2 deletions

View file

@ -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,
},

View file

@ -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<D>(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<Option<OwnedRoomId>> {
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<dyn Iterator<Item = Result<OwnedRoomAliasId>> + 'a> {
self.db.local_aliases_for_room(room_id)
}
}