Skip to content

Commit 787861e

Browse files
authored
fix: Upgrade Ruma
This brings 2 important bug fixes: - Make deprecated fields of `m.room.encrypted` optional: it seems that there are events without these fields in the wild. - Fix deserialization of `RedactedRoomJoinRulesEventContent`. This was found by a bug report in Fractal that caused the same error as #3557 when restoring the client. So maybe we could consider that this bug is fixed? It is still possible that there is another deserialization error. There is also a breaking change in the format of the `state` field in response to `GET /v3/sync`.
1 parent f081416 commit 787861e

File tree

8 files changed

+118
-80
lines changed

8 files changed

+118
-80
lines changed

Cargo.lock

Lines changed: 10 additions & 10 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 = "bbbe39b5b02f2211fdc5e11383c4b66116f19625", features = [
62+
ruma = { git = "https://github.com/ruma/ruma", rev = "a626e6b8521bcaa01bf8b7c4161b26b361b72aff", 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 = "bbbe39b5b02f2211fdc5e11383
7878
"unstable-msc4286",
7979
"unstable-msc4306"
8080
] }
81-
ruma-common = { git = "https://github.com/ruma/ruma", rev = "bbbe39b5b02f2211fdc5e11383c4b66116f19625" }
81+
ruma-common = { git = "https://github.com/ruma/ruma", rev = "a626e6b8521bcaa01bf8b7c4161b26b361b72aff" }
8282
sentry = "0.36.0"
8383
sentry-tracing = "0.36.0"
8484
serde = { version = "1.0.217", features = ["rc"] }

crates/matrix-sdk-base/src/response_processors/room/sync_v2.rs

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ use std::collections::{BTreeMap, BTreeSet};
1616

1717
use ruma::{
1818
OwnedRoomId, OwnedUserId, RoomId,
19-
api::client::sync::sync_events::v3::{InvitedRoom, JoinedRoom, KnockedRoom, LeftRoom},
19+
api::client::sync::sync_events::v3::{InvitedRoom, JoinedRoom, KnockedRoom, LeftRoom, State},
2020
};
2121
use tokio::sync::broadcast::Sender;
22+
use tracing::error;
2223

2324
#[cfg(feature = "e2e-encryption")]
2425
use super::super::e2ee;
@@ -61,39 +62,48 @@ pub async fn update_joined_room(
6162
room_info.mark_state_fully_synced();
6263
room_info.handle_encryption_state(requested_required_states.for_room(room_id));
6364

64-
let (raw_state_events, state_events) = state_events::sync::collect(&joined_room.state.events);
65-
6665
let mut new_user_ids = BTreeSet::new();
6766

68-
state_events::sync::dispatch(
69-
context,
70-
(&raw_state_events, &state_events),
71-
&mut room_info,
72-
ambiguity_cache,
73-
&mut new_user_ids,
74-
state_store,
75-
)
76-
.await?;
67+
let state = match joined_room.state {
68+
State::Before(state) => {
69+
let (raw_state_events, state_events) = state_events::sync::collect(&state.events);
70+
state_events::sync::dispatch(
71+
context,
72+
(&raw_state_events, &state_events),
73+
&mut room_info,
74+
ambiguity_cache,
75+
&mut new_user_ids,
76+
state_store,
77+
)
78+
.await?;
79+
80+
let (raw_state_events_from_timeline, state_events_from_timeline) =
81+
state_events::sync::collect_from_timeline(&joined_room.timeline.events);
82+
state_events::sync::dispatch(
83+
context,
84+
(&raw_state_events_from_timeline, &state_events_from_timeline),
85+
&mut room_info,
86+
ambiguity_cache,
87+
&mut new_user_ids,
88+
state_store,
89+
)
90+
.await?;
91+
92+
state
93+
}
94+
// We shouldn't receive other variants because they are opt-in.
95+
state => {
96+
error!("Unsupported State variant received for joined room: {state:?}");
97+
Default::default()
98+
}
99+
};
77100

78101
ephemeral_events::dispatch(context, &joined_room.ephemeral.events, room_id);
79102

80103
if joined_room.timeline.limited {
81104
room_info.mark_members_missing();
82105
}
83106

84-
let (raw_state_events_from_timeline, state_events_from_timeline) =
85-
state_events::sync::collect_from_timeline(&joined_room.timeline.events);
86-
87-
state_events::sync::dispatch(
88-
context,
89-
(&raw_state_events_from_timeline, &state_events_from_timeline),
90-
&mut room_info,
91-
ambiguity_cache,
92-
&mut new_user_ids,
93-
state_store,
94-
)
95-
.await?;
96-
97107
#[cfg(feature = "e2e-encryption")]
98108
let olm_machine = e2ee.olm_machine;
99109

@@ -145,7 +155,7 @@ pub async fn update_joined_room(
145155

146156
Ok(JoinedRoomUpdate::new(
147157
timeline,
148-
joined_room.state.events,
158+
state.events,
149159
joined_room.account_data.events,
150160
joined_room.ephemeral.events,
151161
notification_count,
@@ -179,30 +189,39 @@ pub async fn update_left_room(
179189
room_info.mark_state_partially_synced();
180190
room_info.handle_encryption_state(requested_required_states.for_room(room_id));
181191

182-
let (raw_state_events, state_events) = state_events::sync::collect(&left_room.state.events);
183-
184-
state_events::sync::dispatch(
185-
context,
186-
(&raw_state_events, &state_events),
187-
&mut room_info,
188-
ambiguity_cache,
189-
&mut (),
190-
state_store,
191-
)
192-
.await?;
193-
194-
let (raw_state_events_from_timeline, state_events_from_timeline) =
195-
state_events::sync::collect_from_timeline(&left_room.timeline.events);
196-
197-
state_events::sync::dispatch(
198-
context,
199-
(&raw_state_events_from_timeline, &state_events_from_timeline),
200-
&mut room_info,
201-
ambiguity_cache,
202-
&mut (),
203-
state_store,
204-
)
205-
.await?;
192+
let state = match left_room.state {
193+
State::Before(state) => {
194+
let (raw_state_events, state_events) = state_events::sync::collect(&state.events);
195+
state_events::sync::dispatch(
196+
context,
197+
(&raw_state_events, &state_events),
198+
&mut room_info,
199+
ambiguity_cache,
200+
&mut (),
201+
state_store,
202+
)
203+
.await?;
204+
205+
let (raw_state_events_from_timeline, state_events_from_timeline) =
206+
state_events::sync::collect_from_timeline(&left_room.timeline.events);
207+
state_events::sync::dispatch(
208+
context,
209+
(&raw_state_events_from_timeline, &state_events_from_timeline),
210+
&mut room_info,
211+
ambiguity_cache,
212+
&mut (),
213+
state_store,
214+
)
215+
.await?;
216+
217+
state
218+
}
219+
// We shouldn't receive other variants because they are opt-in.
220+
state => {
221+
error!("Unsupported State variant received for left room: {state:?}");
222+
Default::default()
223+
}
224+
};
206225

207226
let timeline = timeline::build(
208227
context,
@@ -224,7 +243,7 @@ pub async fn update_left_room(
224243

225244
Ok(LeftRoomUpdate::new(
226245
timeline,
227-
left_room.state.events,
246+
state.events,
228247
left_room.account_data.events,
229248
ambiguity_changes,
230249
))

crates/matrix-sdk-crypto/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ pub enum RoomEventDecryptionResult {
777777
/// # use matrix_sdk_crypto::{
778778
/// # DecryptionSettings, EncryptionSyncChanges, OlmMachine, TrustRequirement
779779
/// # };
780-
/// # use ruma::api::client::sync::sync_events::v3::{Response, JoinedRoom};
780+
/// # use ruma::api::client::sync::sync_events::v3::{Response, State, JoinedRoom};
781781
/// # use ruma::{OwnedUserId, serde::Raw, events::AnySyncStateEvent};
782782
/// # #[tokio::main]
783783
/// # async fn main() -> Result<()> {
@@ -833,10 +833,12 @@ pub enum RoomEventDecryptionResult {
833833
/// for (_, room) in &response.rooms.join {
834834
/// // For simplicity reasons we're only looking at the state field of a joined room, but
835835
/// // the events in the timeline are important as well.
836-
/// for event in &room.state.events {
837-
/// if is_member_event_of_a_joined_user(event) && is_room_encrypted(room) {
838-
/// let user_id = get_user_id(event);
839-
/// users.push(user_id);
836+
/// if let State::Before(state) = &room.state {
837+
/// for event in &state.events {
838+
/// if is_member_event_of_a_joined_user(event) && is_room_encrypted(room) {
839+
/// let user_id = get_user_id(event);
840+
/// users.push(user_id);
841+
/// }
840842
/// }
841843
/// }
842844
/// }

crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,14 @@ pub enum EncryptedMessage {
602602
/// Metadata about an event using the `m.megolm.v1.aes-sha2` algorithm.
603603
MegolmV1AesSha2 {
604604
/// The Curve25519 key of the sender.
605-
#[deprecated = "this field still needs to be sent but should not be used when received"]
605+
#[deprecated = "this field should still be sent but should not be used when received"]
606606
#[doc(hidden)] // Included for Debug formatting only
607-
sender_key: String,
607+
sender_key: Option<String>,
608608

609609
/// The ID of the sending device.
610-
#[deprecated = "this field still needs to be sent but should not be used when received"]
610+
#[deprecated = "this field should still be sent but should not be used when received"]
611611
#[doc(hidden)] // Included for Debug formatting only
612-
device_id: OwnedDeviceId,
612+
device_id: Option<OwnedDeviceId>,
613613

614614
/// The ID of the session used to encrypt the message.
615615
session_id: String,

testing/matrix-sdk-test/src/sync_builder/joined_room.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use ruma::{
99
};
1010
use serde_json::{Value as JsonValue, from_value as from_json_value};
1111

12-
use super::RoomAccountDataTestEvent;
12+
use super::{RoomAccountDataTestEvent, StateMutExt};
1313
use crate::{DEFAULT_TEST_ROOM_ID, event_factory::EventBuilder};
1414

1515
#[derive(Debug, Clone)]
@@ -76,7 +76,7 @@ impl JoinedRoomBuilder {
7676

7777
/// Add an event to the state.
7878
pub fn add_state_event(mut self, event: impl Into<Raw<AnySyncStateEvent>>) -> Self {
79-
self.inner.state.events.push(event.into());
79+
self.inner.state.events_mut().push(event.into());
8080
self
8181
}
8282

@@ -85,7 +85,7 @@ impl JoinedRoomBuilder {
8585
where
8686
I: IntoIterator<Item = Raw<AnySyncStateEvent>>,
8787
{
88-
self.inner.state.events.extend(events);
88+
self.inner.state.events_mut().extend(events);
8989
self
9090
}
9191

testing/matrix-sdk-test/src/sync_builder/left_room.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ruma::{
55
serde::Raw,
66
};
77

8-
use super::{RoomAccountDataTestEvent, StateTestEvent};
8+
use super::{RoomAccountDataTestEvent, StateMutExt, StateTestEvent};
99
use crate::DEFAULT_TEST_ROOM_ID;
1010

1111
pub struct LeftRoomBuilder {
@@ -71,7 +71,7 @@ impl LeftRoomBuilder {
7171

7272
/// Add an event to the state.
7373
pub fn add_state_event(mut self, event: StateTestEvent) -> Self {
74-
self.inner.state.events.push(event.into());
74+
self.inner.state.events_mut().push(event.into());
7575
self
7676
}
7777

@@ -80,7 +80,7 @@ impl LeftRoomBuilder {
8080
where
8181
I: IntoIterator<Item = Raw<AnySyncStateEvent>>,
8282
{
83-
self.inner.state.events.extend(events);
83+
self.inner.state.events_mut().extend(events);
8484
self
8585
}
8686

testing/matrix-sdk-test/src/sync_builder/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ use ruma::{
66
api::{
77
IncomingResponse,
88
client::sync::sync_events::v3::{
9-
InvitedRoom, JoinedRoom, KnockedRoom, LeftRoom, Response as SyncResponse,
9+
InvitedRoom, JoinedRoom, KnockedRoom, LeftRoom, Response as SyncResponse, State,
1010
},
1111
},
12-
events::{AnyGlobalAccountDataEvent, AnyToDeviceEvent, presence::PresenceEvent},
12+
events::{
13+
AnyGlobalAccountDataEvent, AnySyncStateEvent, AnyToDeviceEvent, presence::PresenceEvent,
14+
},
1315
serde::Raw,
1416
};
1517
use serde_json::{Value as JsonValue, from_value as from_json_value, json};
@@ -247,3 +249,18 @@ impl SyncResponseBuilder {
247249
self.presence.clear();
248250
}
249251
}
252+
253+
/// Helper trait to mutate the data in [`State`].
254+
trait StateMutExt {
255+
fn events_mut(&mut self) -> &mut Vec<Raw<AnySyncStateEvent>>;
256+
}
257+
258+
impl StateMutExt for State {
259+
fn events_mut(&mut self) -> &mut Vec<Raw<AnySyncStateEvent>> {
260+
match self {
261+
Self::Before(state) => &mut state.events,
262+
// We don't allow to construct another variant.
263+
_ => unreachable!(),
264+
}
265+
}
266+
}

0 commit comments

Comments
 (0)