base: Add a method to get all joined members.

master
Damir Jelić 2021-01-01 14:58:44 +01:00
parent c804104293
commit 0c81f3d9ae
1 changed files with 13 additions and 31 deletions

View File

@ -110,41 +110,23 @@ impl Room {
self.inner.read().unwrap().base_info.max_power_level self.inner.read().unwrap().base_info.max_power_level
} }
pub async fn get_joined_user_ids(&self) -> impl Stream<Item = UserId> {
self.store.get_joined_user_ids(self.room_id()).await
}
pub async fn get_joined_members(&self) -> impl Stream<Item = RoomMember> + '_ {
let joined = self.store.get_joined_user_ids(self.room_id()).await;
joined.filter_map(move |u| async move { self.get_member(&u).await })
}
pub async fn get_active_members(&self) -> impl Stream<Item = RoomMember> + '_ { pub async fn get_active_members(&self) -> impl Stream<Item = RoomMember> + '_ {
let joined = self.store.get_joined_user_ids(self.room_id()).await; let joined = self.store.get_joined_user_ids(self.room_id()).await;
let invited = self.store.get_invited_user_ids(self.room_id()).await; let invited = self.store.get_invited_user_ids(self.room_id()).await;
let max_power_level = self.max_power_level(); joined
.chain(invited)
let into_member = move |u| async move { .filter_map(move |u| async move { self.get_member(&u).await })
let presence = self.store.get_presence_event(&u).await;
let profile = self.store.get_profile(self.room_id(), &u).await;
let power = self
.store
.get_state_event(self.room_id(), EventType::RoomPowerLevels, "")
.await
.map(|e| {
if let AnySyncStateEvent::RoomPowerLevels(e) = e {
Some(e)
} else {
None
}
})
.flatten();
self.store
.get_member_event(self.room_id(), &u)
.await
.map(|m| RoomMember {
event: m.into(),
profile: profile.into(),
presence: presence.into(),
power_levles: power.into(),
max_power_level,
})
};
joined.chain(invited).filter_map(into_member)
} }
/// Calculate the canonical display name of the room, taking into account /// Calculate the canonical display name of the room, taking into account