From ac2d90e92abd9699e22780462204e1cae488e026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 30 Nov 2020 09:19:11 +0100 Subject: [PATCH] client: Apply room changes when fetching members. --- matrix_sdk_base/src/client.rs | 14 ++++++++------ matrix_sdk_base/src/store.rs | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index a5f769ed..1f0b1406 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -485,9 +485,6 @@ impl BaseClient { } } - // TODO we'll want a flow where we calculate changes using a room - // summary snapshot, then we store the new snapshots, only then do we - // apply and emit the new events and rooms. let mut changes = StateChanges::default(); let mut rooms = Rooms::default(); @@ -558,6 +555,8 @@ impl BaseClient { #[cfg(feature = "encryption")] if summary.is_encrypted() { + // TODO if the room isn't encrypted but the new summary is, + // add all the room users. if let Some(o) = self.olm_machine().await { if let Some(users) = changes.joined_user_ids.get(room_id) { o.update_tracked_users(users).await @@ -581,17 +580,19 @@ impl BaseClient { } self.store.save_changes(&changes).await; - *self.sync_token.write().await = Some(response.next_batch.clone()); + self.apply_changes(changes).await; + Ok(SyncResponse::new(response.next_batch.clone(), rooms)) + } + + async fn apply_changes(&self, changes: StateChanges) { // TODO emit room changes here for (room_id, summary) in changes.room_summaries { if let Some(room) = self.get_joined_room(&room_id) { room.update_summary(summary) } } - - Ok(SyncResponse::new(response.next_batch.clone(), rooms)) } pub async fn receive_members( @@ -637,6 +638,7 @@ impl BaseClient { changes.add_room(summary); self.store.save_changes(&changes).await; + self.apply_changes(changes).await; } Ok(()) diff --git a/matrix_sdk_base/src/store.rs b/matrix_sdk_base/src/store.rs index 93dd3dd7..b575f000 100644 --- a/matrix_sdk_base/src/store.rs +++ b/matrix_sdk_base/src/store.rs @@ -6,7 +6,6 @@ use std::{ }; use futures::{ - executor::block_on, future, stream::{self, Stream, StreamExt}, }; @@ -266,6 +265,10 @@ impl Room { } } + pub fn own_user_id(&self) -> &UserId { + &self.own_user_id + } + pub(crate) fn clone_summary(&self) -> InnerSummary { (*self.inner.lock().unwrap()).clone() }