From b02e1da471913b3d9dc40643b714acdaea79d3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 1 Aug 2025 11:52:04 +0200 Subject: [PATCH] Upgrade Ruma MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This brings in a new breaking change from Ruma, because not all events are stripped in a room's stripped state. For simplicity, this still considers the events as stripped during deserialization for now, since this format is compatible with the other possible formats. Signed-off-by: Kévin Commaille --- Cargo.lock | 16 ++++++------ Cargo.toml | 4 +-- .../src/deserialized_responses.rs | 15 +++++------ .../response_processors/room/msc4186/mod.rs | 3 ++- .../src/response_processors/state_events.rs | 25 +++++++++++++------ .../src/store/integration_tests.rs | 14 ++++++----- .../matrix-sdk-base/src/store/memory_store.rs | 7 +++--- crates/matrix-sdk-base/src/store/mod.rs | 17 ++++++------- .../tests/sliding_sync/notification_client.rs | 2 +- testing/matrix-sdk-test/src/lib.rs | 2 +- .../src/sync_builder/invited_room.rs | 9 ++++--- .../src/sync_builder/knocked_room.rs | 7 +++--- .../src/sync_builder/test_event.rs | 7 +++--- 13 files changed, 73 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d33fd1c2..bb7d53189 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4423,7 +4423,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.12.5" -source = "git+https://github.com/ruma/ruma?rev=184d4f85b201bc1e932a8344d78575e826f31efa#184d4f85b201bc1e932a8344d78575e826f31efa" +source = "git+https://github.com/ruma/ruma?rev=bbbe39b5b02f2211fdc5e11383c4b66116f19625#bbbe39b5b02f2211fdc5e11383c4b66116f19625" dependencies = [ "assign", "js_int", @@ -4439,7 +4439,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.20.4" -source = "git+https://github.com/ruma/ruma?rev=184d4f85b201bc1e932a8344d78575e826f31efa#184d4f85b201bc1e932a8344d78575e826f31efa" +source = "git+https://github.com/ruma/ruma?rev=bbbe39b5b02f2211fdc5e11383c4b66116f19625#bbbe39b5b02f2211fdc5e11383c4b66116f19625" dependencies = [ "as_variant", "assign", @@ -4462,7 +4462,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.15.4" -source = "git+https://github.com/ruma/ruma?rev=184d4f85b201bc1e932a8344d78575e826f31efa#184d4f85b201bc1e932a8344d78575e826f31efa" +source = "git+https://github.com/ruma/ruma?rev=bbbe39b5b02f2211fdc5e11383c4b66116f19625#bbbe39b5b02f2211fdc5e11383c4b66116f19625" dependencies = [ "as_variant", "base64", @@ -4495,7 +4495,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.30.4" -source = "git+https://github.com/ruma/ruma?rev=184d4f85b201bc1e932a8344d78575e826f31efa#184d4f85b201bc1e932a8344d78575e826f31efa" +source = "git+https://github.com/ruma/ruma?rev=bbbe39b5b02f2211fdc5e11383c4b66116f19625#bbbe39b5b02f2211fdc5e11383c4b66116f19625" dependencies = [ "as_variant", "indexmap", @@ -4521,7 +4521,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.11.2" -source = "git+https://github.com/ruma/ruma?rev=184d4f85b201bc1e932a8344d78575e826f31efa#184d4f85b201bc1e932a8344d78575e826f31efa" +source = "git+https://github.com/ruma/ruma?rev=bbbe39b5b02f2211fdc5e11383c4b66116f19625#bbbe39b5b02f2211fdc5e11383c4b66116f19625" dependencies = [ "headers", "http", @@ -4539,7 +4539,7 @@ dependencies = [ [[package]] name = "ruma-html" version = "0.4.1" -source = "git+https://github.com/ruma/ruma?rev=184d4f85b201bc1e932a8344d78575e826f31efa#184d4f85b201bc1e932a8344d78575e826f31efa" +source = "git+https://github.com/ruma/ruma?rev=bbbe39b5b02f2211fdc5e11383c4b66116f19625#bbbe39b5b02f2211fdc5e11383c4b66116f19625" dependencies = [ "as_variant", "html5ever", @@ -4550,7 +4550,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.10.1" -source = "git+https://github.com/ruma/ruma?rev=184d4f85b201bc1e932a8344d78575e826f31efa#184d4f85b201bc1e932a8344d78575e826f31efa" +source = "git+https://github.com/ruma/ruma?rev=bbbe39b5b02f2211fdc5e11383c4b66116f19625#bbbe39b5b02f2211fdc5e11383c4b66116f19625" dependencies = [ "js_int", "thiserror 2.0.11", @@ -4559,7 +4559,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.15.2" -source = "git+https://github.com/ruma/ruma?rev=184d4f85b201bc1e932a8344d78575e826f31efa#184d4f85b201bc1e932a8344d78575e826f31efa" +source = "git+https://github.com/ruma/ruma?rev=bbbe39b5b02f2211fdc5e11383c4b66116f19625#bbbe39b5b02f2211fdc5e11383c4b66116f19625" dependencies = [ "cfg-if", "proc-macro-crate", diff --git a/Cargo.toml b/Cargo.toml index dc42946fb..3fb003915 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ proptest = { version = "1.6.0", default-features = false, features = ["std"] } rand = "0.8.5" reqwest = { version = "0.12.12", default-features = false } rmp-serde = "1.3.0" -ruma = { git = "https://github.com/ruma/ruma", rev = "184d4f85b201bc1e932a8344d78575e826f31efa", features = [ +ruma = { git = "https://github.com/ruma/ruma", rev = "bbbe39b5b02f2211fdc5e11383c4b66116f19625", features = [ "client-api-c", "compat-upload-signatures", "compat-arbitrary-length-ids", @@ -78,7 +78,7 @@ ruma = { git = "https://github.com/ruma/ruma", rev = "184d4f85b201bc1e932a8344d7 "unstable-msc4286", "unstable-msc4306" ] } -ruma-common = { git = "https://github.com/ruma/ruma", rev = "184d4f85b201bc1e932a8344d78575e826f31efa" } +ruma-common = { git = "https://github.com/ruma/ruma", rev = "bbbe39b5b02f2211fdc5e11383c4b66116f19625" } sentry = "0.36.0" sentry-tracing = "0.36.0" serde = { version = "1.0.217", features = ["rc"] } diff --git a/crates/matrix-sdk-base/src/deserialized_responses.rs b/crates/matrix-sdk-base/src/deserialized_responses.rs index eda956b50..2c7002b3c 100644 --- a/crates/matrix-sdk-base/src/deserialized_responses.rs +++ b/crates/matrix-sdk-base/src/deserialized_responses.rs @@ -21,8 +21,9 @@ use once_cell::sync::Lazy; use regex::Regex; use ruma::{ EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, UInt, UserId, + api::client::sync::sync_events::StrippedState, events::{ - AnyStrippedStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, EventContentFromType, + AnySyncStateEvent, AnySyncTimelineEvent, EventContentFromType, PossiblyRedactedStateEventContent, RedactContent, RedactedStateEventContent, StateEventContent, StaticStateEventContent, StrippedStateEvent, SyncStateEvent, room::{ @@ -261,7 +262,7 @@ pub enum RawAnySyncOrStrippedTimelineEvent { /// An event from a room in joined or left state. Sync(Raw), /// An event from a room in invited state. - Stripped(Raw), + Stripped(Raw), } impl From> for RawAnySyncOrStrippedTimelineEvent { @@ -270,8 +271,8 @@ impl From> for RawAnySyncOrStrippedTimelineEvent { } } -impl From> for RawAnySyncOrStrippedTimelineEvent { - fn from(event: Raw) -> Self { +impl From> for RawAnySyncOrStrippedTimelineEvent { + fn from(event: Raw) -> Self { Self::Stripped(event) } } @@ -283,7 +284,7 @@ pub enum RawAnySyncOrStrippedState { /// An event from a room in joined or left state. Sync(Raw), /// An event from a room in invited state. - Stripped(Raw), + Stripped(Raw), } impl RawAnySyncOrStrippedState { @@ -323,7 +324,7 @@ pub enum AnySyncOrStrippedState { /// /// The value is `Box`ed because it is quite large. Let's keep the size of /// `Self` as small as possible. - Stripped(Box), + Stripped(Box), } impl AnySyncOrStrippedState { @@ -338,7 +339,7 @@ impl AnySyncOrStrippedState { /// If this is an `AnyStrippedStateEvent`, return a reference to the inner /// event. - pub fn as_stripped(&self) -> Option<&AnyStrippedStateEvent> { + pub fn as_stripped(&self) -> Option<&StrippedState> { match self { Self::Sync(_) => None, Self::Stripped(ev) => Some(ev), diff --git a/crates/matrix-sdk-base/src/response_processors/room/msc4186/mod.rs b/crates/matrix-sdk-base/src/response_processors/room/msc4186/mod.rs index 6ce12b9a7..a6a69d3a0 100644 --- a/crates/matrix-sdk-base/src/response_processors/room/msc4186/mod.rs +++ b/crates/matrix-sdk-base/src/response_processors/room/msc4186/mod.rs @@ -23,6 +23,7 @@ use matrix_sdk_common::deserialized_responses::TimelineEvent; use ruma::{ JsOption, OwnedRoomId, RoomId, UserId, api::client::sync::sync_events::{ + StrippedState, v3::{InviteState, InvitedRoom, KnockState, KnockedRoom}, v5 as http, }, @@ -225,7 +226,7 @@ pub async fn update_any_room( fn membership( context: &mut Context, state_events: &[AnySyncStateEvent], - invite_state_events: &Option<(Vec>, Vec)>, + invite_state_events: &Option<(Vec>, Vec)>, store: &BaseStateStore, user_id: &UserId, room_id: &RoomId, diff --git a/crates/matrix-sdk-base/src/response_processors/state_events.rs b/crates/matrix-sdk-base/src/response_processors/state_events.rs index 6eede82a3..b991d2709 100644 --- a/crates/matrix-sdk-base/src/response_processors/state_events.rs +++ b/crates/matrix-sdk-base/src/response_processors/state_events.rs @@ -212,8 +212,10 @@ pub mod sync { pub mod stripped { use std::{collections::BTreeMap, iter}; - use ruma::{events::AnyStrippedStateEvent, push::Action}; - use tracing::instrument; + use ruma::{ + api::client::sync::sync_events::StrippedState, events::AnyStrippedStateEvent, push::Action, + }; + use tracing::{instrument, warn}; use super::{ super::{notification, timeline}, @@ -221,11 +223,20 @@ pub mod stripped { }; use crate::{Result, Room, RoomInfo}; - /// Collect [`AnyStrippedStateEvent`] to [`AnyStrippedStateEvent`]. + /// Collect [`Raw`] to [`AnyStrippedStateEvent`]. pub fn collect( - raw_events: &[Raw], - ) -> (Vec>, Vec) { - super::collect(raw_events) + raw_events: &[Raw], + ) -> (Vec>, Vec) { + raw_events + .iter() + .filter_map(|raw_event| match raw_event.deserialize_as() { + Ok(event) => Some((raw_event.clone(), event)), + Err(e) => { + warn!("Couldn't deserialize stripped state event: {e}"); + None + } + }) + .unzip() } /// Dispatch the stripped state events. @@ -247,7 +258,7 @@ pub mod stripped { #[instrument(skip_all, fields(room_id = ?room_info.room_id))] pub(crate) async fn dispatch_invite_or_knock( context: &mut Context, - (raw_events, events): (&[Raw], &[AnyStrippedStateEvent]), + (raw_events, events): (&[Raw], &[AnyStrippedStateEvent]), room: &Room, room_info: &mut RoomInfo, mut notification: notification::Notification<'_>, diff --git a/crates/matrix-sdk-base/src/store/integration_tests.rs b/crates/matrix-sdk-base/src/store/integration_tests.rs index 5fce2c576..cccbe8df2 100644 --- a/crates/matrix-sdk-base/src/store/integration_tests.rs +++ b/crates/matrix-sdk-base/src/store/integration_tests.rs @@ -10,13 +10,16 @@ use ruma::{ EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, RoomId, TransactionId, UserId, api::{ FeatureFlag, MatrixVersion, - client::discovery::discover_homeserver::{HomeserverInfo, RtcFocusInfo}, + client::{ + discovery::discover_homeserver::{HomeserverInfo, RtcFocusInfo}, + sync::sync_events::StrippedState, + }, }, event_id, events::{ AnyGlobalAccountDataEvent, AnyMessageLikeEventContent, AnyRoomAccountDataEvent, - AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType, - RoomAccountDataEventType, StateEventType, SyncStateEvent, + AnySyncStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType, + SyncStateEvent, presence::PresenceEvent, receipt::{ReceiptThread, ReceiptType}, room::{ @@ -195,9 +198,8 @@ impl StateStoreIntegrationTests for DynStateStore { let stripped_name_json: &JsonValue = &test_json::NAME_STRIPPED; let stripped_name_raw = - serde_json::from_value::>(stripped_name_json.clone()) - .unwrap(); - let stripped_name_event = stripped_name_raw.deserialize().unwrap(); + serde_json::from_value::>(stripped_name_json.clone()).unwrap(); + let stripped_name_event = stripped_name_raw.deserialize_as().unwrap(); stripped_room.handle_stripped_state_event(&stripped_name_event); changes.stripped_state.insert( stripped_room_id.to_owned(), diff --git a/crates/matrix-sdk-base/src/store/memory_store.rs b/crates/matrix-sdk-base/src/store/memory_store.rs index 55eb80635..d7c058902 100644 --- a/crates/matrix-sdk-base/src/store/memory_store.rs +++ b/crates/matrix-sdk-base/src/store/memory_store.rs @@ -23,10 +23,11 @@ use matrix_sdk_common::{ROOM_VERSION_FALLBACK, ROOM_VERSION_RULES_FALLBACK}; use ruma::{ CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedMxcUri, OwnedRoomId, OwnedTransactionId, OwnedUserId, RoomId, TransactionId, UserId, + api::client::sync::sync_events::StrippedState, canonical_json::{RedactedBecause, redact}, events::{ - AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent, - AnySyncStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType, + AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncStateEvent, + GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType, presence::PresenceEvent, receipt::{Receipt, ReceiptThread, ReceiptType}, room::member::{MembershipState, StrippedRoomMemberEvent, SyncRoomMemberEvent}, @@ -68,7 +69,7 @@ struct MemoryStoreInner { room_account_data: HashMap>>, stripped_room_state: - HashMap>>>, + HashMap>>>, stripped_members: HashMap>, presence: HashMap>, room_user_receipts: HashMap< diff --git a/crates/matrix-sdk-base/src/store/mod.rs b/crates/matrix-sdk-base/src/store/mod.rs index a1efb1898..996d38c33 100644 --- a/crates/matrix-sdk-base/src/store/mod.rs +++ b/crates/matrix-sdk-base/src/store/mod.rs @@ -47,11 +47,12 @@ pub use matrix_sdk_store_encryption::Error as StoreEncryptionError; use observable_map::ObservableMap; use ruma::{ EventId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId, + api::client::sync::sync_events::StrippedState, events::{ - AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent, - AnySyncStateEvent, EmptyStateKey, GlobalAccountDataEventType, RedactContent, - RedactedStateEventContent, RoomAccountDataEventType, StateEventType, StaticEventContent, - StaticStateEventContent, StrippedStateEvent, SyncStateEvent, + AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncStateEvent, EmptyStateKey, + GlobalAccountDataEventType, RedactContent, RedactedStateEventContent, + RoomAccountDataEventType, StateEventType, StaticEventContent, StaticStateEventContent, + StrippedStateEvent, SyncStateEvent, presence::PresenceEvent, receipt::ReceiptEventContent, room::{ @@ -531,11 +532,9 @@ pub struct StateChanges { pub redactions: BTreeMap>>, /// A mapping of `RoomId` to a map of event type to a map of state key to - /// `AnyStrippedStateEvent`. - pub stripped_state: BTreeMap< - OwnedRoomId, - BTreeMap>>, - >, + /// `StrippedState`. + pub stripped_state: + BTreeMap>>>, /// A map from room id to a map of a display name and a set of user ids that /// share that display name in the given room. diff --git a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs index 42b8e5fcd..7013b5258 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs @@ -70,7 +70,7 @@ async fn test_notification() -> Result<()> { }; if let Some(event_id) = invited_room.invite_state.events.iter().find_map(|event| { - let Ok(AnyStrippedStateEvent::RoomMember(room_member_ev)) = event.deserialize() else { + let Ok(AnyStrippedStateEvent::RoomMember(room_member_ev)) = event.deserialize_as() else { return None; }; diff --git a/testing/matrix-sdk-test/src/lib.rs b/testing/matrix-sdk-test/src/lib.rs index b96e3fc09..637fb3576 100644 --- a/testing/matrix-sdk-test/src/lib.rs +++ b/testing/matrix-sdk-test/src/lib.rs @@ -66,7 +66,7 @@ macro_rules! stripped_state_event { ($( $tt:tt )*) => { ::ruma::serde::Raw::new(&::serde_json::json!( $($tt)* )) .unwrap() - .cast_unchecked::<::ruma::events::AnyStrippedStateEvent>() + .cast_unchecked::<::ruma::api::client::sync::sync_events::StrippedState>() } } diff --git a/testing/matrix-sdk-test/src/sync_builder/invited_room.rs b/testing/matrix-sdk-test/src/sync_builder/invited_room.rs index 842a86be3..cddfba80f 100644 --- a/testing/matrix-sdk-test/src/sync_builder/invited_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/invited_room.rs @@ -1,6 +1,7 @@ use ruma::{ - OwnedRoomId, RoomId, api::client::sync::sync_events::v3::InvitedRoom, - events::AnyStrippedStateEvent, serde::Raw, + OwnedRoomId, RoomId, + api::client::sync::sync_events::{StrippedState, v3::InvitedRoom}, + serde::Raw, }; use crate::DEFAULT_TEST_ROOM_ID; @@ -25,7 +26,7 @@ impl InvitedRoomBuilder { } /// Add an event to the state. - pub fn add_state_event(mut self, event: impl Into>) -> Self { + pub fn add_state_event(mut self, event: impl Into>) -> Self { self.inner.invite_state.events.push(event.into()); self } @@ -33,7 +34,7 @@ impl InvitedRoomBuilder { /// Add events to the state in bulk. pub fn add_state_bulk(mut self, events: I) -> Self where - I: IntoIterator>, + I: IntoIterator>, { self.inner.invite_state.events.extend(events); self diff --git a/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs b/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs index 065636ab4..9c548041a 100644 --- a/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs +++ b/testing/matrix-sdk-test/src/sync_builder/knocked_room.rs @@ -1,6 +1,7 @@ use ruma::{ - OwnedRoomId, RoomId, api::client::sync::sync_events::v3::KnockedRoom, - events::AnyStrippedStateEvent, serde::Raw, + OwnedRoomId, RoomId, + api::client::sync::sync_events::{StrippedState, v3::KnockedRoom}, + serde::Raw, }; use super::StrippedStateTestEvent; @@ -34,7 +35,7 @@ impl KnockedRoomBuilder { /// Add events to the state in bulk. pub fn add_state_bulk(mut self, events: I) -> Self where - I: IntoIterator>, + I: IntoIterator>, { self.inner.knock_state.events.extend(events); self diff --git a/testing/matrix-sdk-test/src/sync_builder/test_event.rs b/testing/matrix-sdk-test/src/sync_builder/test_event.rs index 3d864804a..9b2b36910 100644 --- a/testing/matrix-sdk-test/src/sync_builder/test_event.rs +++ b/testing/matrix-sdk-test/src/sync_builder/test_event.rs @@ -1,7 +1,8 @@ use ruma::{ + api::client::sync::sync_events::StrippedState, events::{ - AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent, - AnySyncStateEvent, presence::PresenceEvent, + AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncStateEvent, + presence::PresenceEvent, }, serde::Raw, }; @@ -89,7 +90,7 @@ impl From for JsonValue { } } -impl From for Raw { +impl From for Raw { fn from(val: StrippedStateTestEvent) -> Self { from_json_value(val.into()).unwrap() }