Skip to content

Commit a9f22d1

Browse files
committed
feat(sdk): Migrate from SS to SSS.
This patch migrates the code from SS to SSS. It means that `sort` and `bump_event_types` in lists, or room unsubscriptions, in the requests are removed, or `timestamp` migrates to `bump_stamp` etc.
1 parent 9961db5 commit a9f22d1

File tree

31 files changed

+355
-582
lines changed

31 files changed

+355
-582
lines changed

bindings/matrix-sdk-ffi/src/room_list.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ use std::{fmt::Debug, mem::MaybeUninit, ptr::addr_of_mut, sync::Arc, time::Durat
33
use eyeball_im::VectorDiff;
44
use futures_util::{pin_mut, StreamExt, TryFutureExt};
55
use matrix_sdk::ruma::{
6-
api::client::sync::sync_events::{
7-
v4::RoomSubscription as RumaRoomSubscription,
8-
UnreadNotificationsCount as RumaUnreadNotificationsCount,
9-
},
6+
api::client::sync::sync_events::UnreadNotificationsCount as RumaUnreadNotificationsCount,
107
assign, RoomId,
118
};
9+
use matrix_sdk::sliding_sync::http;
1210
use matrix_sdk_ui::{
1311
room_list_service::filters::{
1412
new_filter_all, new_filter_any, new_filter_category, new_filter_favourite,
@@ -653,10 +651,6 @@ impl RoomListItem {
653651
self.inner.subscribe(settings.map(Into::into));
654652
}
655653

656-
fn unsubscribe(&self) {
657-
self.inner.unsubscribe();
658-
}
659-
660654
async fn latest_event(&self) -> Option<Arc<EventTimelineItem>> {
661655
self.inner.latest_event().await.map(EventTimelineItem).map(Arc::new)
662656
}
@@ -675,9 +669,9 @@ pub struct RoomSubscription {
675669
pub include_heroes: Option<bool>,
676670
}
677671

678-
impl From<RoomSubscription> for RumaRoomSubscription {
672+
impl From<RoomSubscription> for http::RequestRoomSubscription {
679673
fn from(val: RoomSubscription) -> Self {
680-
assign!(RumaRoomSubscription::default(), {
674+
assign!(http::RequestRoomSubscription::default(), {
681675
required_state: val.required_state.map(|r|
682676
r.into_iter().map(|s| (s.key.into(), s.value)).collect()
683677
).unwrap_or_default(),

crates/matrix-sdk-base/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ experimental-sliding-sync = [
2626
"ruma/unstable-msc3575",
2727
"ruma/unstable-simplified-msc3575",
2828
]
29+
experimental-simplified-sliding-sync = ["experimental-sliding-sync"]
2930
uniffi = ["dep:uniffi", "matrix-sdk-crypto?/uniffi"]
3031

3132
# helpers for testing features build upon this

crates/matrix-sdk-base/src/rooms/normal.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use bitflags::bitflags;
2424
use eyeball::{SharedObservable, Subscriber};
2525
#[cfg(all(feature = "e2e-encryption", feature = "experimental-sliding-sync"))]
2626
use matrix_sdk_common::ring_buffer::RingBuffer;
27+
#[cfg(feature = "experimental-sliding-sync")]
28+
use ruma::events::AnySyncTimelineEvent;
2729
use ruma::{
2830
api::client::sync::sync_events::v3::RoomSummary as RumaSummary,
2931
events::{
@@ -49,8 +51,6 @@ use ruma::{
4951
EventId, MxcUri, OwnedEventId, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedUserId,
5052
RoomAliasId, RoomId, RoomVersionId, UserId,
5153
};
52-
#[cfg(feature = "experimental-sliding-sync")]
53-
use ruma::{events::AnySyncTimelineEvent, MilliSecondsSinceUnixEpoch};
5454
use serde::{Deserialize, Serialize};
5555
use tokio::sync::broadcast;
5656
use tracing::{debug, field::debug, info, instrument, warn};
@@ -91,8 +91,8 @@ bitflags! {
9191
/// The reason why a [`RoomInfoNotableUpdate`] is emitted.
9292
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9393
pub struct RoomInfoNotableUpdateReasons: u8 {
94-
/// The recency timestamp of the `Room` has changed.
95-
const RECENCY_TIMESTAMP = 0b0000_0001;
94+
/// The recency stamp of the `Room` has changed.
95+
const RECENCY_STAMP = 0b0000_0001;
9696

9797
/// The latest event of the `Room` has changed.
9898
const LATEST_EVENT = 0b0000_0010;
@@ -923,12 +923,12 @@ impl Room {
923923
self.inner.read().base_info.is_marked_unread
924924
}
925925

926-
/// Returns the recency timestamp of the room.
926+
/// Returns the recency stamp of the room.
927927
///
928-
/// Please read `RoomInfo::recency_timestamp` to learn more.
928+
/// Please read `RoomInfo::recency_stamp` to learn more.
929929
#[cfg(feature = "experimental-sliding-sync")]
930-
pub fn recency_timestamp(&self) -> Option<MilliSecondsSinceUnixEpoch> {
931-
self.inner.read().recency_timestamp
930+
pub fn recency_stamp(&self) -> Option<u64> {
931+
self.inner.read().recency_stamp
932932
}
933933
}
934934

@@ -989,15 +989,15 @@ pub struct RoomInfo {
989989
#[serde(default, skip_serializing_if = "Option::is_none")]
990990
pub(crate) cached_display_name: Option<DisplayName>,
991991

992-
/// The recency timestamp of this room.
992+
/// The recency stamp of this room.
993993
///
994994
/// It's not to be confused with `origin_server_ts` of the latest event.
995995
/// Sliding Sync might "ignore” some events when computing the recency
996-
/// timestamp of the room. Thus, using this `recency_timestamp` value is
996+
/// stamp of the room. Thus, using this `recency_stamp` value is
997997
/// more accurate than relying on the latest event.
998998
#[cfg(feature = "experimental-sliding-sync")]
999999
#[serde(default)]
1000-
pub(crate) recency_timestamp: Option<MilliSecondsSinceUnixEpoch>,
1000+
pub(crate) recency_stamp: Option<u64>,
10011001
}
10021002

10031003
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
@@ -1036,7 +1036,7 @@ impl RoomInfo {
10361036
warned_about_unknown_room_version: Arc::new(false.into()),
10371037
cached_display_name: None,
10381038
#[cfg(feature = "experimental-sliding-sync")]
1039-
recency_timestamp: None,
1039+
recency_stamp: None,
10401040
}
10411041
}
10421042

@@ -1442,12 +1442,12 @@ impl RoomInfo {
14421442
self.latest_event.as_deref()
14431443
}
14441444

1445-
/// Updates the recency timestamp of this room.
1445+
/// Updates the recency stamp of this room.
14461446
///
1447-
/// Please read [`Self::recency_timestamp`] to learn more.
1447+
/// Please read [`Self::recency_stamp`] to learn more.
14481448
#[cfg(feature = "experimental-sliding-sync")]
1449-
pub(crate) fn update_recency_timestamp(&mut self, timestamp: MilliSecondsSinceUnixEpoch) {
1450-
self.recency_timestamp = Some(timestamp);
1449+
pub(crate) fn update_recency_stamp(&mut self, stamp: u64) {
1450+
self.recency_stamp = Some(stamp);
14511451
}
14521452
}
14531453

@@ -1663,7 +1663,7 @@ mod tests {
16631663
read_receipts: Default::default(),
16641664
warned_about_unknown_room_version: Arc::new(false.into()),
16651665
cached_display_name: None,
1666-
recency_timestamp: Some(MilliSecondsSinceUnixEpoch(42u32.into())),
1666+
recency_stamp: Some(42),
16671667
};
16681668

16691669
let info_json = json!({
@@ -1716,7 +1716,7 @@ mod tests {
17161716
"latest_active": null,
17171717
"pending": []
17181718
},
1719-
"recency_timestamp": 42,
1719+
"recency_stamp": 42,
17201720
});
17211721

17221722
assert_eq!(serde_json::to_value(info).unwrap(), info_json);

crates/matrix-sdk-base/src/sliding_sync/http.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,30 @@ where
6363
}
6464

6565
mod ss {
66-
use super::{sss, From};
6766
use ruma::{api::client::sync::sync_events::v4, events::TimelineEventType};
68-
67+
// Response types.
68+
pub use v4::{
69+
Extensions as ResponseExtensions, Response, SlidingSyncRoom as ResponseRoom,
70+
SlidingSyncRoomHero as ResponseRoomHero, SyncList as ResponseList,
71+
};
6972
// Request types.
7073
pub use v4::{
7174
ExtensionsConfig as RequestExtensions, Request, RoomDetailsConfig as RequestRoomDetails,
7275
RoomSubscription as RequestRoomSubscription, SyncRequestList as RequestList,
7376
SyncRequestListFilters as RequestListFilters,
7477
};
7578

76-
// Response types.
77-
pub use v4::{
78-
Extensions as ResponseExtensions, Response, SlidingSyncRoom as ResponseRoom,
79-
SlidingSyncRoomHero as ResponseRoomHero, SyncList as ResponseList,
80-
};
79+
use super::{sss, From};
8180

8281
pub mod extensions {
8382
// Request types.
84-
pub use super::v4::{
85-
AccountDataConfig as RequestAccountData, E2EEConfig as RequestE2EE,
86-
ReceiptsConfig as RequestReceipts, RoomReceiptConfig as RequestReceiptsRoom,
87-
ToDeviceConfig as RequestToDevice, TypingConfig as RequestTyping,
88-
};
89-
9083
// Response types.
9184
pub use super::v4::{
92-
AccountData as ResponseAccountData, Receipts as ResponseReceipts,
93-
ToDevice as ResponseToDevice, Typing as ResponseTyping, E2EE as ResponseE2EE,
85+
AccountData as ResponseAccountData, AccountDataConfig as RequestAccountData,
86+
E2EEConfig as RequestE2EE, Receipts as ResponseReceipts,
87+
ReceiptsConfig as RequestReceipts, RoomReceiptConfig as RequestReceiptsRoom,
88+
ToDevice as ResponseToDevice, ToDeviceConfig as RequestToDevice,
89+
Typing as ResponseTyping, TypingConfig as RequestTyping, E2EE as ResponseE2EE,
9490
};
9591
}
9692

@@ -118,7 +114,9 @@ mod ss {
118114
s.room_details = From::from(value.room_details);
119115
s.include_heroes = value.include_heroes;
120116
s.filters = From::from(value.filters);
121-
s.sort = vec!["by_recency".to_string(), "by_name".to_string()];
117+
118+
// Defaults from Simplified MSC3575.
119+
s.sort = vec!["by_recency".to_owned(), "by_name".to_owned()];
122120
s.bump_event_types = vec![
123121
TimelineEventType::RoomMessage,
124122
TimelineEventType::RoomEncrypted,
@@ -248,9 +246,10 @@ mod ss {
248246
}
249247

250248
mod sss {
251-
use super::{ss, From};
252249
pub use ruma::api::client::sync::sync_events::v5::*;
253250

251+
use super::{ss, From};
252+
254253
impl From<ss::Response> for Response {
255254
fn from(value: ss::Response) -> Self {
256255
let mut s = Self::new(value.pos);

0 commit comments

Comments
 (0)