client: Add the get_x_room methods back.

master
Damir Jelić 2021-01-01 14:57:39 +01:00
parent 0952205e1e
commit c804104293
2 changed files with 31 additions and 12 deletions

View File

@ -550,20 +550,32 @@ impl Client {
self.base_client.add_event_emitter(emitter).await; self.base_client.add_event_emitter(emitter).await;
} }
// /// Returns the joined rooms this client knows about. /// Returns the joined rooms this client knows about.
// pub fn joined_rooms(&self) -> Arc<RwLock<HashMap<RoomId, Arc<RwLock<Room>>>>> { pub fn joined_rooms(&self) -> Vec<JoinedRoom> {
// self.base_client.joined_rooms() self.store()
// } .get_rooms()
.into_iter()
.filter_map(|r| r.joined())
.collect()
}
// /// Returns the invited rooms this client knows about. /// Returns the invited rooms this client knows about.
// pub fn invited_rooms(&self) -> Arc<RwLock<HashMap<RoomId, Arc<RwLock<Room>>>>> { pub fn invited_rooms(&self) -> Vec<InvitedRoom> {
// self.base_client.invited_rooms() self.store()
// } .get_rooms()
.into_iter()
.filter_map(|r| r.invited())
.collect()
}
// /// Returns the left rooms this client knows about. /// Returns the left rooms this client knows about.
// pub fn left_rooms(&self) -> Arc<RwLock<HashMap<RoomId, Arc<RwLock<Room>>>>> { pub fn left_rooms(&self) -> Vec<LeftRoom> {
// self.base_client.left_rooms() self.store()
// } .get_rooms()
.into_iter()
.filter_map(|r| r.left())
.collect()
}
/// Get a joined room with the given room id. /// Get a joined room with the given room id.
/// ///

View File

@ -76,6 +76,13 @@ impl Store {
self.rooms.get(room_id).map(|r| r.clone()) self.rooms.get(room_id).map(|r| r.clone())
} }
pub fn get_rooms(&self) -> Vec<RoomState> {
self.rooms
.iter()
.filter_map(|r| self.get_room(r.key()))
.collect()
}
pub fn get_joined_room(&self, room_id: &RoomId) -> Option<JoinedRoom> { pub fn get_joined_room(&self, room_id: &RoomId) -> Option<JoinedRoom> {
self.get_room(room_id).map(|r| r.joined()).flatten() self.get_room(room_id).map(|r| r.joined()).flatten()
} }