From b4d0179c181d269df42a456a6032c6aea4a3e950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 30 Nov 2020 14:55:18 +0100 Subject: [PATCH] base: Fetch the member presence when we fetch members. --- matrix_sdk_base/src/store.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/matrix_sdk_base/src/store.rs b/matrix_sdk_base/src/store.rs index aeca57df..959e1621 100644 --- a/matrix_sdk_base/src/store.rs +++ b/matrix_sdk_base/src/store.rs @@ -175,10 +175,15 @@ impl Room { let invited = self.store.get_invited_user_ids(self.room_id()).await; let x = move |u| async move { + let presence = self.store.get_presence_event(&u).await; + self.store .get_member_event(self.room_id(), &u) .await - .map(|m| m.into()) + .map(|m| RoomMember { + event: m.into(), + presence: presence.into(), + }) }; joined.chain(invited).filter_map(x) @@ -294,10 +299,15 @@ impl Room { } pub async fn get_member(&self, user_id: &UserId) -> Option { + let presence = self.store.get_presence_event(user_id).await; + self.store .get_member_event(&self.room_id, user_id) .await - .map(|e| e.into()) + .map(|e| RoomMember { + event: e.into(), + presence: presence.into(), + }) } pub fn room_id(&self) -> &RoomId { @@ -316,6 +326,7 @@ impl Room { #[derive(Clone, Debug)] pub struct RoomMember { event: Arc>, + presence: Arc>, } impl RoomMember { @@ -340,14 +351,6 @@ impl RoomMember { } } -impl From> for RoomMember { - fn from(event: SyncStateEvent) -> Self { - Self { - event: Arc::new(event), - } - } -} - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct InnerSummary { room_id: Arc, @@ -577,6 +580,13 @@ impl Store { self.inner.flush_async().await.unwrap(); } + pub async fn get_presence_event(&self, user_id: &UserId) -> Option { + self.presence + .get(user_id.as_bytes()) + .unwrap() + .map(|e| serde_json::from_slice(&e).unwrap()) + } + pub async fn get_member_event( &self, room_id: &RoomId,