mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-24 17:18:23 -04:00
bindings: Reset the timeline when the user's ignore list is updated
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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<OlmMachine>,
|
||||
pub(crate) ignore_user_list_changes_tx: Arc<SharedObservable<()>>,
|
||||
}
|
||||
|
||||
#[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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user