mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-06 06:53:32 -04:00
feat(sdk): Add support for bump_event_types in SlidingSync
feat(sdk): Add support for `bump_event_types` in `SlidingSync`
This commit is contained in:
@@ -871,6 +871,14 @@ impl SlidingSyncBuilder {
|
||||
Arc::new(builder)
|
||||
}
|
||||
|
||||
pub fn bump_event_types(self: Arc<Self>, bump_event_types: Vec<String>) -> Arc<Self> {
|
||||
let mut builder = unwrap_or_clone_arc(self);
|
||||
builder.inner = builder.inner.bump_event_types(
|
||||
bump_event_types.into_iter().map(Into::into).collect::<Vec<_>>().as_slice(),
|
||||
);
|
||||
Arc::new(builder)
|
||||
}
|
||||
|
||||
pub fn build(self: Arc<Self>) -> Result<Arc<SlidingSync>, ClientError> {
|
||||
let builder = unwrap_or_clone_arc(self);
|
||||
RUNTIME.block_on(async move {
|
||||
|
||||
@@ -10,7 +10,9 @@ use ruma::{
|
||||
self, AccountDataConfig, E2EEConfig, ExtensionsConfig, ReceiptsConfig, ToDeviceConfig,
|
||||
TypingConfig,
|
||||
},
|
||||
assign, OwnedRoomId,
|
||||
assign,
|
||||
events::TimelineEventType,
|
||||
OwnedRoomId,
|
||||
};
|
||||
use url::Url;
|
||||
|
||||
@@ -30,6 +32,7 @@ pub struct SlidingSyncBuilder {
|
||||
homeserver: Option<Url>,
|
||||
client: Option<Client>,
|
||||
lists: BTreeMap<String, SlidingSyncList>,
|
||||
bump_event_types: Vec<TimelineEventType>,
|
||||
extensions: Option<ExtensionsConfig>,
|
||||
subscriptions: BTreeMap<OwnedRoomId, v4::RoomSubscription>,
|
||||
}
|
||||
@@ -41,6 +44,7 @@ impl SlidingSyncBuilder {
|
||||
homeserver: None,
|
||||
client: None,
|
||||
lists: BTreeMap::new(),
|
||||
bump_event_types: Vec::new(),
|
||||
extensions: None,
|
||||
subscriptions: BTreeMap::new(),
|
||||
}
|
||||
@@ -189,6 +193,17 @@ impl SlidingSyncBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Allowlist of event types which should be considered recent activity
|
||||
/// when sorting `by_recency`. By omitting event types, clients can ensure
|
||||
/// that uninteresting events (e.g. a profile rename) do not cause a
|
||||
/// room to jump to the top of its list(s). Empty or
|
||||
/// omitted `bump_event_types` have no effect: all events in a room will
|
||||
/// be considered recent activity.
|
||||
pub fn bump_event_types(mut self, bump_event_types: &[TimelineEventType]) -> Self {
|
||||
self.bump_event_types = bump_event_types.to_vec();
|
||||
self
|
||||
}
|
||||
|
||||
/// Build the Sliding Sync.
|
||||
///
|
||||
/// If `self.storage_key` is `Some(_)`, load the cached data from cold
|
||||
@@ -222,6 +237,7 @@ impl SlidingSyncBuilder {
|
||||
|
||||
lists,
|
||||
rooms,
|
||||
bump_event_types: self.bump_event_types,
|
||||
|
||||
extensions: Mutex::new(self.extensions),
|
||||
reset_counter: Default::default(),
|
||||
|
||||
@@ -49,7 +49,9 @@ use ruma::{
|
||||
self, AccountDataConfig, E2EEConfig, ExtensionsConfig, ToDeviceConfig,
|
||||
},
|
||||
},
|
||||
assign, OwnedRoomId, RoomId,
|
||||
assign,
|
||||
events::TimelineEventType,
|
||||
OwnedRoomId, RoomId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::{spawn, sync::Mutex as AsyncMutex};
|
||||
@@ -100,13 +102,17 @@ pub(super) struct SlidingSyncInner {
|
||||
/// The rooms details
|
||||
rooms: StdRwLock<BTreeMap<OwnedRoomId, SlidingSyncRoom>>,
|
||||
|
||||
/// The `bump_event_types` field. See
|
||||
/// [`SlidingSyncBuilder::bump_event_types`] to learn more.
|
||||
bump_event_types: Vec<TimelineEventType>,
|
||||
|
||||
subscriptions: StdRwLock<BTreeMap<OwnedRoomId, v4::RoomSubscription>>,
|
||||
unsubscribe: StdRwLock<Vec<OwnedRoomId>>,
|
||||
|
||||
/// Number of times a Sliding Session session has been reset.
|
||||
reset_counter: AtomicU8,
|
||||
|
||||
/// the intended state of the extensions being supplied to sliding /sync
|
||||
/// The intended state of the extensions being supplied to sliding /sync
|
||||
/// calls. May contain the latest next_batch for to_devices, etc.
|
||||
extensions: Mutex<Option<ExtensionsConfig>>,
|
||||
}
|
||||
@@ -411,6 +417,7 @@ impl SlidingSync {
|
||||
txn_id: Some(stream_id.to_owned()),
|
||||
timeout: Some(timeout),
|
||||
lists: requests_lists,
|
||||
bump_event_types: self.inner.bump_event_types.clone(),
|
||||
room_subscriptions,
|
||||
unsubscribe_rooms,
|
||||
extensions,
|
||||
|
||||
Reference in New Issue
Block a user