Skip to content

feat: Migrate from Sliding Sync to Simplified Sliding Sync #3676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ once_cell = "1.16.0"
pin-project-lite = "0.2.9"
rand = "0.8.5"
reqwest = { version = "0.12.4", default-features = false }
ruma = { git = "https://github.com/ruma/ruma", rev = "c37843e9be619ffac8c4d33ad3a6a175cc32610c", features = [
ruma = { git = "https://github.com/matrix-org/ruma", rev = "4d3d8b46fd519012e4585ccf00dbea1eb602c028", features = [
"client-api-c",
"compat-upload-signatures",
"compat-user-id",
Expand All @@ -59,7 +59,7 @@ ruma = { git = "https://github.com/ruma/ruma", rev = "c37843e9be619ffac8c4d33ad3
"unstable-msc4075",
"unstable-msc4140",
] }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "c37843e9be619ffac8c4d33ad3a6a175cc32610c" }
ruma-common = { git = "https://github.com/matrix-org/ruma", rev = "4d3d8b46fd519012e4585ccf00dbea1eb602c028" }
serde = "1.0.151"
serde_html_form = "0.2.0"
serde_json = "1.0.91"
Expand Down
12 changes: 12 additions & 0 deletions bindings/matrix-sdk-ffi/src/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ pub struct ClientBuilder {
user_agent: Option<String>,
requires_sliding_sync: bool,
sliding_sync_proxy: Option<String>,
is_simplified_sliding_sync_enabled: bool,
proxy: Option<String>,
disable_ssl_verification: bool,
disable_automatic_token_refresh: bool,
Expand All @@ -272,6 +273,8 @@ impl ClientBuilder {
user_agent: None,
requires_sliding_sync: false,
sliding_sync_proxy: None,
// By default, Simplified MSC3575 is turned off.
is_simplified_sliding_sync_enabled: false,
proxy: None,
disable_ssl_verification: false,
disable_automatic_token_refresh: false,
Expand Down Expand Up @@ -366,6 +369,12 @@ impl ClientBuilder {
Arc::new(builder)
}

pub fn simplified_sliding_sync(self: Arc<Self>, enable: bool) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.is_simplified_sliding_sync_enabled = enable;
Arc::new(builder)
}

pub fn proxy(self: Arc<Self>, url: String) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.proxy = Some(url);
Expand Down Expand Up @@ -499,6 +508,9 @@ impl ClientBuilder {

inner_builder = inner_builder.with_encryption_settings(builder.encryption_settings);

inner_builder =
inner_builder.simplified_sliding_sync(builder.is_simplified_sliding_sync_enabled);

if builder.requires_sliding_sync {
inner_builder = inner_builder.requires_sliding_sync();
}
Expand Down
18 changes: 7 additions & 11 deletions bindings/matrix-sdk-ffi/src/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use std::{fmt::Debug, mem::MaybeUninit, ptr::addr_of_mut, sync::Arc, time::Durat

use eyeball_im::VectorDiff;
use futures_util::{pin_mut, StreamExt, TryFutureExt};
use matrix_sdk::ruma::{
api::client::sync::sync_events::{
v4::RoomSubscription as RumaRoomSubscription,
UnreadNotificationsCount as RumaUnreadNotificationsCount,
use matrix_sdk::{
ruma::{
api::client::sync::sync_events::UnreadNotificationsCount as RumaUnreadNotificationsCount,
assign, RoomId,
},
assign, RoomId,
sliding_sync::http,
};
use matrix_sdk_ui::{
room_list_service::filters::{
Expand Down Expand Up @@ -653,10 +653,6 @@ impl RoomListItem {
self.inner.subscribe(settings.map(Into::into));
}

fn unsubscribe(&self) {
self.inner.unsubscribe();
}

async fn latest_event(&self) -> Option<Arc<EventTimelineItem>> {
self.inner.latest_event().await.map(EventTimelineItem).map(Arc::new)
}
Expand All @@ -675,9 +671,9 @@ pub struct RoomSubscription {
pub include_heroes: Option<bool>,
}

impl From<RoomSubscription> for RumaRoomSubscription {
impl From<RoomSubscription> for http::request::RoomSubscription {
fn from(val: RoomSubscription) -> Self {
assign!(RumaRoomSubscription::default(), {
assign!(http::request::RoomSubscription::default(), {
required_state: val.required_state.map(|r|
r.into_iter().map(|s| (s.key.into(), s.value)).collect()
).unwrap_or_default(),
Expand Down
5 changes: 4 additions & 1 deletion crates/matrix-sdk-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ js = ["matrix-sdk-common/js", "matrix-sdk-crypto?/js", "ruma/js", "matrix-sdk-st
qrcode = ["matrix-sdk-crypto?/qrcode"]
automatic-room-key-forwarding = ["matrix-sdk-crypto?/automatic-room-key-forwarding"]
message-ids = ["matrix-sdk-crypto?/message-ids"]
experimental-sliding-sync = ["ruma/unstable-msc3575"]
experimental-sliding-sync = [
"ruma/unstable-msc3575",
"ruma/unstable-simplified-msc3575",
]
uniffi = ["dep:uniffi", "matrix-sdk-crypto?/uniffi"]

# helpers for testing features build upon this
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod rooms;
pub mod read_receipts;
pub use read_receipts::PreviousEventsProvider;
#[cfg(feature = "experimental-sliding-sync")]
mod sliding_sync;
pub mod sliding_sync;

pub mod store;
pub mod sync;
Expand Down
36 changes: 18 additions & 18 deletions crates/matrix-sdk-base/src/rooms/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use bitflags::bitflags;
use eyeball::{SharedObservable, Subscriber};
#[cfg(all(feature = "e2e-encryption", feature = "experimental-sliding-sync"))]
use matrix_sdk_common::ring_buffer::RingBuffer;
#[cfg(feature = "experimental-sliding-sync")]
use ruma::events::AnySyncTimelineEvent;
use ruma::{
api::client::sync::sync_events::v3::RoomSummary as RumaSummary,
events::{
Expand All @@ -49,8 +51,6 @@ use ruma::{
EventId, MxcUri, OwnedEventId, OwnedMxcUri, OwnedRoomAliasId, OwnedRoomId, OwnedUserId,
RoomAliasId, RoomId, RoomVersionId, UserId,
};
#[cfg(feature = "experimental-sliding-sync")]
use ruma::{events::AnySyncTimelineEvent, MilliSecondsSinceUnixEpoch};
use serde::{Deserialize, Serialize};
use tokio::sync::broadcast;
use tracing::{debug, field::debug, info, instrument, warn};
Expand Down Expand Up @@ -91,8 +91,8 @@ bitflags! {
/// The reason why a [`RoomInfoNotableUpdate`] is emitted.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct RoomInfoNotableUpdateReasons: u8 {
/// The recency timestamp of the `Room` has changed.
const RECENCY_TIMESTAMP = 0b0000_0001;
/// The recency stamp of the `Room` has changed.
const RECENCY_STAMP = 0b0000_0001;

/// The latest event of the `Room` has changed.
const LATEST_EVENT = 0b0000_0010;
Expand Down Expand Up @@ -940,12 +940,12 @@ impl Room {
self.inner.read().base_info.is_marked_unread
}

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

Expand Down Expand Up @@ -1006,15 +1006,15 @@ pub struct RoomInfo {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) cached_display_name: Option<DisplayName>,

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

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
Expand Down Expand Up @@ -1053,7 +1053,7 @@ impl RoomInfo {
warned_about_unknown_room_version: Arc::new(false.into()),
cached_display_name: None,
#[cfg(feature = "experimental-sliding-sync")]
recency_timestamp: None,
recency_stamp: None,
}
}

Expand Down Expand Up @@ -1459,12 +1459,12 @@ impl RoomInfo {
self.latest_event.as_deref()
}

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

Expand Down Expand Up @@ -1675,7 +1675,7 @@ mod tests {
read_receipts: Default::default(),
warned_about_unknown_room_version: Arc::new(false.into()),
cached_display_name: None,
recency_timestamp: Some(MilliSecondsSinceUnixEpoch(42u32.into())),
recency_stamp: Some(42),
};

let info_json = json!({
Expand Down Expand Up @@ -1728,7 +1728,7 @@ mod tests {
"latest_active": null,
"pending": []
},
"recency_timestamp": 42,
"recency_stamp": 42,
});

assert_eq!(serde_json::to_value(info).unwrap(), info_json);
Expand Down
50 changes: 50 additions & 0 deletions crates/matrix-sdk-base/src/sliding_sync/http.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! HTTP types for (Simplified) MSC3575.
//!
//! This module provides unified namings for types from MSC3575 and
//! Simplified MSC3575, in addition to provide conversion from one
//! format to another.

/// HTTP types from MSC3575, renamed to match the Simplified MSC3575 namings.
pub mod msc3575 {
use ruma::api::client::sync::sync_events::v4;
pub use v4::{Request, Response};

/// HTTP types related to a `Request`.
pub mod request {
pub use super::v4::{
AccountDataConfig as AccountData, ExtensionsConfig as Extensions,
ReceiptsConfig as Receipts, RoomDetailsConfig as RoomDetails, RoomSubscription,
SyncRequestList as List, SyncRequestListFilters as ListFilters,
ToDeviceConfig as ToDevice, TypingConfig as Typing,
};
}

/// HTTP types related to a `Response`.
pub mod response {
pub use super::v4::{
AccountData, Extensions, Receipts, SlidingSyncRoom as Room,
SlidingSyncRoomHero as RoomHero, SyncList as List, ToDevice, Typing,
};
}
}

/// HTTP types from Simplified MSC3575.
pub mod simplified_msc3575 {
pub use ruma::api::client::sync::sync_events::v5::*;
}

pub use simplified_msc3575::*;
Loading
Loading