Skip to content

Commit

Permalink
bindings: Reset the timeline when the user's ignore list is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Mar 30, 2023
1 parent f988106 commit ca6faff
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
21 changes: 19 additions & 2 deletions bindings/matrix-sdk-ffi/src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
18 changes: 15 additions & 3 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -89,6 +90,7 @@ pub struct BaseClient {
/// [`BaseClient::set_session_meta`]
#[cfg(feature = "e2e-encryption")]
olm_machine: OnceCell<OlmMachine>,
pub(crate) ignore_user_list_changes_tx: Arc<SharedObservable<()>>,
}

#[cfg(not(tarpaulin_include))]
Expand Down Expand Up @@ -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(),
}
}

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions crates/matrix-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ca6faff

Please sign in to comment.