improvement: load aliases from database
This commit is contained in:
parent
18bf67748c
commit
9c26e22ad7
2 changed files with 18 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue