improvement: load aliases from database

This commit is contained in:
timokoesters 2020-05-24 08:30:57 +02:00
parent 18bf67748c
commit 9c26e22ad7
No known key found for this signature in database
GPG key ID: 356E705610F626D5
2 changed files with 18 additions and 6 deletions

View file

@ -26,6 +26,8 @@ pub struct Rooms {
pub(super) roomid_pduleaves: sled::Tree,
pub(super) roomstateid_pdu: sled::Tree, // RoomStateId = Room + StateType + StateKey
pub(super) alias_roomid: sled::Tree,
pub(super) userroomid_joined: sled::Tree,
pub(super) roomuserid_joined: sled::Tree,
pub(super) userroomid_invited: sled::Tree,
@ -646,6 +648,16 @@ impl Rooms {
Ok(())
}
pub fn id_from_alias(&self, alias: &str) -> Result<Option<RoomId>> {
if !alias.starts_with('#') {
return Err(Error::BadRequest("room alias does not start with #"));
}
self.alias_roomid.get(alias)?.map_or(Ok(None), |bytes| {
Ok(Some(RoomId::try_from(utils::string_from_bytes(&bytes)?)?))
})
}
/// Returns an iterator over all rooms a user joined.
pub fn room_members(&self, room_id: &RoomId) -> impl Iterator<Item = Result<UserId>> {
self.roomuserid_joined