diff --git a/bindings/matrix-sdk-ffi/src/sliding_sync.rs b/bindings/matrix-sdk-ffi/src/sliding_sync.rs index af03e3b6548..88b3f0d4514 100644 --- a/bindings/matrix-sdk-ffi/src/sliding_sync.rs +++ b/bindings/matrix-sdk-ffi/src/sliding_sync.rs @@ -2,7 +2,7 @@ use std::sync::{Arc, RwLock}; use anyhow::Context; use eyeball_im::VectorDiff; -use futures_util::{future::join3, pin_mut, StreamExt}; +use futures_util::{future::join4, pin_mut, StreamExt}; use matrix_sdk::ruma::{ api::client::sync::sync_events::{ v4::RoomSubscription as RumaRoomSubscription, @@ -229,9 +229,26 @@ impl SlidingSyncRoom { } }; + // This in the future could be removed, and the rx handling could be moved + // inside handle_sliding_sync_reset since we want to reset the sliding + // sync for ignore user list events + let handle_ignore_user_list_changes = { + let ignore_user_list_change_rx = self.client.subscribe_to_ignore_user_list_changes(); + let timeline = timeline.to_owned(); + async move { + ignore_user_list_change_rx.for_each(|_| timeline.clear()).await; + } + }; + let items = timeline_items.into_iter().map(TimelineItem::from_arc).collect(); let task_handle = TaskHandle::new(RUNTIME.spawn(async move { - join3(handle_events, handle_sliding_sync_reset, handle_sync_gap).await; + join4( + handle_events, + handle_sliding_sync_reset, + handle_sync_gap, + handle_ignore_user_list_changes, + ) + .await; })); Ok((items, task_handle)) diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index 10305e5acad..326d7d5d01f 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -13,15 +13,16 @@ // See the License for the specific language governing permissions and // limitations under the License. +#[cfg(feature = "e2e-encryption")] +use std::ops::Deref; use std::{ borrow::Borrow, collections::{BTreeMap, BTreeSet}, fmt, + sync::Arc, }; -#[cfg(feature = "e2e-encryption")] -use std::{ops::Deref, sync::Arc}; -use eyeball::Subscriber; +use eyeball::{shared::Observable as SharedObservable, Subscriber}; use matrix_sdk_common::instant::Instant; #[cfg(feature = "e2e-encryption")] use matrix_sdk_crypto::{ @@ -89,6 +90,7 @@ pub struct BaseClient { /// [`BaseClient::set_session_meta`] #[cfg(feature = "e2e-encryption")] olm_machine: OnceCell, + pub(crate) ignore_user_list_changes_tx: Arc>, } #[cfg(not(tarpaulin_include))] @@ -120,6 +122,7 @@ impl BaseClient { crypto_store: config.crypto_store, #[cfg(feature = "e2e-encryption")] olm_machine: Default::default(), + ignore_user_list_changes_tx: Default::default(), } } @@ -894,6 +897,9 @@ impl BaseClient { } pub(crate) async fn apply_changes(&self, changes: &StateChanges) { + if changes.account_data.contains_key(&GlobalAccountDataEventType::IgnoredUserList) { + self.ignore_user_list_changes_tx.set(()); + } for (room_id, room_info) in &changes.room_infos { if let Some(room) = self.store.get_room(room_id) { room.update_summary(room_info.clone()) @@ -1227,6 +1233,12 @@ impl BaseClient { push_rules.notification_power_levels = room_power_levels.notifications; } } + + /// Returns a subscriber that publishes an event every time the ignore user + /// list changes + pub fn subscribe_to_ignore_user_list_changes(&self) -> Subscriber<()> { + self.ignore_user_list_changes_tx.subscribe() + } } impl Default for BaseClient { diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 5259a64c69c..df371fa4882 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -210,6 +210,12 @@ impl Client { .map_err(ClientBuildError::assert_valid_builder_args) } + /// Returns a subscriber that publishes an event every time the ignore user + /// list changes. + pub fn subscribe_to_ignore_user_list_changes(&self) -> Subscriber<()> { + self.inner.base_client.subscribe_to_ignore_user_list_changes() + } + /// Create a new [`ClientBuilder`]. pub fn builder() -> ClientBuilder { ClientBuilder::new()