Skip to content

Commit b02e1da

Browse files
zecakehpoljar
authored andcommitted
Upgrade Ruma
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 <[email protected]>
1 parent 5ad477a commit b02e1da

File tree

13 files changed

+73
-55
lines changed

13 files changed

+73
-55
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ proptest = { version = "1.6.0", default-features = false, features = ["std"] }
5959
rand = "0.8.5"
6060
reqwest = { version = "0.12.12", default-features = false }
6161
rmp-serde = "1.3.0"
62-
ruma = { git = "https://github.com/ruma/ruma", rev = "184d4f85b201bc1e932a8344d78575e826f31efa", features = [
62+
ruma = { git = "https://github.com/ruma/ruma", rev = "bbbe39b5b02f2211fdc5e11383c4b66116f19625", features = [
6363
"client-api-c",
6464
"compat-upload-signatures",
6565
"compat-arbitrary-length-ids",
@@ -78,7 +78,7 @@ ruma = { git = "https://github.com/ruma/ruma", rev = "184d4f85b201bc1e932a8344d7
7878
"unstable-msc4286",
7979
"unstable-msc4306"
8080
] }
81-
ruma-common = { git = "https://github.com/ruma/ruma", rev = "184d4f85b201bc1e932a8344d78575e826f31efa" }
81+
ruma-common = { git = "https://github.com/ruma/ruma", rev = "bbbe39b5b02f2211fdc5e11383c4b66116f19625" }
8282
sentry = "0.36.0"
8383
sentry-tracing = "0.36.0"
8484
serde = { version = "1.0.217", features = ["rc"] }

crates/matrix-sdk-base/src/deserialized_responses.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ use once_cell::sync::Lazy;
2121
use regex::Regex;
2222
use ruma::{
2323
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, OwnedUserId, UInt, UserId,
24+
api::client::sync::sync_events::StrippedState,
2425
events::{
25-
AnyStrippedStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, EventContentFromType,
26+
AnySyncStateEvent, AnySyncTimelineEvent, EventContentFromType,
2627
PossiblyRedactedStateEventContent, RedactContent, RedactedStateEventContent,
2728
StateEventContent, StaticStateEventContent, StrippedStateEvent, SyncStateEvent,
2829
room::{
@@ -261,7 +262,7 @@ pub enum RawAnySyncOrStrippedTimelineEvent {
261262
/// An event from a room in joined or left state.
262263
Sync(Raw<AnySyncTimelineEvent>),
263264
/// An event from a room in invited state.
264-
Stripped(Raw<AnyStrippedStateEvent>),
265+
Stripped(Raw<StrippedState>),
265266
}
266267

267268
impl From<Raw<AnySyncTimelineEvent>> for RawAnySyncOrStrippedTimelineEvent {
@@ -270,8 +271,8 @@ impl From<Raw<AnySyncTimelineEvent>> for RawAnySyncOrStrippedTimelineEvent {
270271
}
271272
}
272273

273-
impl From<Raw<AnyStrippedStateEvent>> for RawAnySyncOrStrippedTimelineEvent {
274-
fn from(event: Raw<AnyStrippedStateEvent>) -> Self {
274+
impl From<Raw<StrippedState>> for RawAnySyncOrStrippedTimelineEvent {
275+
fn from(event: Raw<StrippedState>) -> Self {
275276
Self::Stripped(event)
276277
}
277278
}
@@ -283,7 +284,7 @@ pub enum RawAnySyncOrStrippedState {
283284
/// An event from a room in joined or left state.
284285
Sync(Raw<AnySyncStateEvent>),
285286
/// An event from a room in invited state.
286-
Stripped(Raw<AnyStrippedStateEvent>),
287+
Stripped(Raw<StrippedState>),
287288
}
288289

289290
impl RawAnySyncOrStrippedState {
@@ -323,7 +324,7 @@ pub enum AnySyncOrStrippedState {
323324
///
324325
/// The value is `Box`ed because it is quite large. Let's keep the size of
325326
/// `Self` as small as possible.
326-
Stripped(Box<AnyStrippedStateEvent>),
327+
Stripped(Box<StrippedState>),
327328
}
328329

329330
impl AnySyncOrStrippedState {
@@ -338,7 +339,7 @@ impl AnySyncOrStrippedState {
338339

339340
/// If this is an `AnyStrippedStateEvent`, return a reference to the inner
340341
/// event.
341-
pub fn as_stripped(&self) -> Option<&AnyStrippedStateEvent> {
342+
pub fn as_stripped(&self) -> Option<&StrippedState> {
342343
match self {
343344
Self::Sync(_) => None,
344345
Self::Stripped(ev) => Some(ev),

crates/matrix-sdk-base/src/response_processors/room/msc4186/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use matrix_sdk_common::deserialized_responses::TimelineEvent;
2323
use ruma::{
2424
JsOption, OwnedRoomId, RoomId, UserId,
2525
api::client::sync::sync_events::{
26+
StrippedState,
2627
v3::{InviteState, InvitedRoom, KnockState, KnockedRoom},
2728
v5 as http,
2829
},
@@ -225,7 +226,7 @@ pub async fn update_any_room(
225226
fn membership(
226227
context: &mut Context,
227228
state_events: &[AnySyncStateEvent],
228-
invite_state_events: &Option<(Vec<Raw<AnyStrippedStateEvent>>, Vec<AnyStrippedStateEvent>)>,
229+
invite_state_events: &Option<(Vec<Raw<StrippedState>>, Vec<AnyStrippedStateEvent>)>,
229230
store: &BaseStateStore,
230231
user_id: &UserId,
231232
room_id: &RoomId,

crates/matrix-sdk-base/src/response_processors/state_events.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,31 @@ pub mod sync {
212212
pub mod stripped {
213213
use std::{collections::BTreeMap, iter};
214214

215-
use ruma::{events::AnyStrippedStateEvent, push::Action};
216-
use tracing::instrument;
215+
use ruma::{
216+
api::client::sync::sync_events::StrippedState, events::AnyStrippedStateEvent, push::Action,
217+
};
218+
use tracing::{instrument, warn};
217219

218220
use super::{
219221
super::{notification, timeline},
220222
Context, Raw,
221223
};
222224
use crate::{Result, Room, RoomInfo};
223225

224-
/// Collect [`AnyStrippedStateEvent`] to [`AnyStrippedStateEvent`].
226+
/// Collect [`Raw<StrippedState>`] to [`AnyStrippedStateEvent`].
225227
pub fn collect(
226-
raw_events: &[Raw<AnyStrippedStateEvent>],
227-
) -> (Vec<Raw<AnyStrippedStateEvent>>, Vec<AnyStrippedStateEvent>) {
228-
super::collect(raw_events)
228+
raw_events: &[Raw<StrippedState>],
229+
) -> (Vec<Raw<StrippedState>>, Vec<AnyStrippedStateEvent>) {
230+
raw_events
231+
.iter()
232+
.filter_map(|raw_event| match raw_event.deserialize_as() {
233+
Ok(event) => Some((raw_event.clone(), event)),
234+
Err(e) => {
235+
warn!("Couldn't deserialize stripped state event: {e}");
236+
None
237+
}
238+
})
239+
.unzip()
229240
}
230241

231242
/// Dispatch the stripped state events.
@@ -247,7 +258,7 @@ pub mod stripped {
247258
#[instrument(skip_all, fields(room_id = ?room_info.room_id))]
248259
pub(crate) async fn dispatch_invite_or_knock(
249260
context: &mut Context,
250-
(raw_events, events): (&[Raw<AnyStrippedStateEvent>], &[AnyStrippedStateEvent]),
261+
(raw_events, events): (&[Raw<StrippedState>], &[AnyStrippedStateEvent]),
251262
room: &Room,
252263
room_info: &mut RoomInfo,
253264
mut notification: notification::Notification<'_>,

crates/matrix-sdk-base/src/store/integration_tests.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ use ruma::{
1010
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId, RoomId, TransactionId, UserId,
1111
api::{
1212
FeatureFlag, MatrixVersion,
13-
client::discovery::discover_homeserver::{HomeserverInfo, RtcFocusInfo},
13+
client::{
14+
discovery::discover_homeserver::{HomeserverInfo, RtcFocusInfo},
15+
sync::sync_events::StrippedState,
16+
},
1417
},
1518
event_id,
1619
events::{
1720
AnyGlobalAccountDataEvent, AnyMessageLikeEventContent, AnyRoomAccountDataEvent,
18-
AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType,
19-
RoomAccountDataEventType, StateEventType, SyncStateEvent,
21+
AnySyncStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType,
22+
SyncStateEvent,
2023
presence::PresenceEvent,
2124
receipt::{ReceiptThread, ReceiptType},
2225
room::{
@@ -195,9 +198,8 @@ impl StateStoreIntegrationTests for DynStateStore {
195198

196199
let stripped_name_json: &JsonValue = &test_json::NAME_STRIPPED;
197200
let stripped_name_raw =
198-
serde_json::from_value::<Raw<AnyStrippedStateEvent>>(stripped_name_json.clone())
199-
.unwrap();
200-
let stripped_name_event = stripped_name_raw.deserialize().unwrap();
201+
serde_json::from_value::<Raw<StrippedState>>(stripped_name_json.clone()).unwrap();
202+
let stripped_name_event = stripped_name_raw.deserialize_as().unwrap();
201203
stripped_room.handle_stripped_state_event(&stripped_name_event);
202204
changes.stripped_state.insert(
203205
stripped_room_id.to_owned(),

crates/matrix-sdk-base/src/store/memory_store.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ use matrix_sdk_common::{ROOM_VERSION_FALLBACK, ROOM_VERSION_RULES_FALLBACK};
2323
use ruma::{
2424
CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedMxcUri,
2525
OwnedRoomId, OwnedTransactionId, OwnedUserId, RoomId, TransactionId, UserId,
26+
api::client::sync::sync_events::StrippedState,
2627
canonical_json::{RedactedBecause, redact},
2728
events::{
28-
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent,
29-
AnySyncStateEvent, GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType,
29+
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncStateEvent,
30+
GlobalAccountDataEventType, RoomAccountDataEventType, StateEventType,
3031
presence::PresenceEvent,
3132
receipt::{Receipt, ReceiptThread, ReceiptType},
3233
room::member::{MembershipState, StrippedRoomMemberEvent, SyncRoomMemberEvent},
@@ -68,7 +69,7 @@ struct MemoryStoreInner {
6869
room_account_data:
6970
HashMap<OwnedRoomId, HashMap<RoomAccountDataEventType, Raw<AnyRoomAccountDataEvent>>>,
7071
stripped_room_state:
71-
HashMap<OwnedRoomId, HashMap<StateEventType, HashMap<String, Raw<AnyStrippedStateEvent>>>>,
72+
HashMap<OwnedRoomId, HashMap<StateEventType, HashMap<String, Raw<StrippedState>>>>,
7273
stripped_members: HashMap<OwnedRoomId, HashMap<OwnedUserId, MembershipState>>,
7374
presence: HashMap<OwnedUserId, Raw<PresenceEvent>>,
7475
room_user_receipts: HashMap<

crates/matrix-sdk-base/src/store/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ pub use matrix_sdk_store_encryption::Error as StoreEncryptionError;
4747
use observable_map::ObservableMap;
4848
use ruma::{
4949
EventId, OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId,
50+
api::client::sync::sync_events::StrippedState,
5051
events::{
51-
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent,
52-
AnySyncStateEvent, EmptyStateKey, GlobalAccountDataEventType, RedactContent,
53-
RedactedStateEventContent, RoomAccountDataEventType, StateEventType, StaticEventContent,
54-
StaticStateEventContent, StrippedStateEvent, SyncStateEvent,
52+
AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnySyncStateEvent, EmptyStateKey,
53+
GlobalAccountDataEventType, RedactContent, RedactedStateEventContent,
54+
RoomAccountDataEventType, StateEventType, StaticEventContent, StaticStateEventContent,
55+
StrippedStateEvent, SyncStateEvent,
5556
presence::PresenceEvent,
5657
receipt::ReceiptEventContent,
5758
room::{
@@ -531,11 +532,9 @@ pub struct StateChanges {
531532
pub redactions: BTreeMap<OwnedRoomId, BTreeMap<OwnedEventId, Raw<SyncRoomRedactionEvent>>>,
532533

533534
/// A mapping of `RoomId` to a map of event type to a map of state key to
534-
/// `AnyStrippedStateEvent`.
535-
pub stripped_state: BTreeMap<
536-
OwnedRoomId,
537-
BTreeMap<StateEventType, BTreeMap<String, Raw<AnyStrippedStateEvent>>>,
538-
>,
535+
/// `StrippedState`.
536+
pub stripped_state:
537+
BTreeMap<OwnedRoomId, BTreeMap<StateEventType, BTreeMap<String, Raw<StrippedState>>>>,
539538

540539
/// A map from room id to a map of a display name and a set of user ids that
541540
/// share that display name in the given room.

testing/matrix-sdk-integration-testing/src/tests/sliding_sync/notification_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async fn test_notification() -> Result<()> {
7070
};
7171

7272
if let Some(event_id) = invited_room.invite_state.events.iter().find_map(|event| {
73-
let Ok(AnyStrippedStateEvent::RoomMember(room_member_ev)) = event.deserialize() else {
73+
let Ok(AnyStrippedStateEvent::RoomMember(room_member_ev)) = event.deserialize_as() else {
7474
return None;
7575
};
7676

testing/matrix-sdk-test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ macro_rules! stripped_state_event {
6666
($( $tt:tt )*) => {
6767
::ruma::serde::Raw::new(&::serde_json::json!( $($tt)* ))
6868
.unwrap()
69-
.cast_unchecked::<::ruma::events::AnyStrippedStateEvent>()
69+
.cast_unchecked::<::ruma::api::client::sync::sync_events::StrippedState>()
7070
}
7171
}
7272

0 commit comments

Comments
 (0)