From 27ad1f42da2f0d7c9c9c0778f17b7bd89d56ae9d Mon Sep 17 00:00:00 2001 From: Sorunome Date: Sat, 3 Jul 2021 12:00:13 +0200 Subject: [PATCH 1/2] use hoist_and_deserialize for state events --- matrix_sdk/src/event_handler/mod.rs | 9 +++++---- matrix_sdk_base/src/client.rs | 2 +- matrix_sdk_base/src/lib.rs | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/matrix_sdk/src/event_handler/mod.rs b/matrix_sdk/src/event_handler/mod.rs index 5b21b0a7..e7cf2105 100644 --- a/matrix_sdk/src/event_handler/mod.rs +++ b/matrix_sdk/src/event_handler/mod.rs @@ -14,6 +14,7 @@ // limitations under the License. use std::ops::Deref; +use matrix_sdk_base::{hoist_and_deserialize_state_event, hoist_room_event_prev_content}; use matrix_sdk_common::async_trait; use ruma::{ api::client::r0::push::get_notifications::Notification, @@ -91,7 +92,7 @@ impl Handler { } for (raw_event, event) in room_info.state.events.iter().filter_map(|e| { - if let Ok(d) = e.deserialize() { + if let Ok(d) = hoist_and_deserialize_state_event(e) { Some((e, d)) } else { None @@ -101,7 +102,7 @@ impl Handler { } for (raw_event, event) in room_info.timeline.events.iter().filter_map(|e| { - if let Ok(d) = e.event.deserialize() { + if let Ok(d) = hoist_room_event_prev_content(&e.event) { Some((&e.event, d)) } else { None @@ -121,7 +122,7 @@ impl Handler { } for (raw_event, event) in room_info.state.events.iter().filter_map(|e| { - if let Ok(d) = e.deserialize() { + if let Ok(d) = hoist_and_deserialize_state_event(e) { Some((e, d)) } else { None @@ -131,7 +132,7 @@ impl Handler { } for (raw_event, event) in room_info.timeline.events.iter().filter_map(|e| { - if let Ok(d) = e.event.deserialize() { + if let Ok(d) = hoist_room_event_prev_content(&e.event) { Some((&e.event, d)) } else { None diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index b36d9041..7c7497ea 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -129,7 +129,7 @@ fn hoist_member_event( Ok(e) } -fn hoist_room_event_prev_content( +pub fn hoist_room_event_prev_content( event: &Raw, ) -> StdResult { let prev_content = event diff --git a/matrix_sdk_base/src/lib.rs b/matrix_sdk_base/src/lib.rs index 326700ce..051f2181 100644 --- a/matrix_sdk_base/src/lib.rs +++ b/matrix_sdk_base/src/lib.rs @@ -50,7 +50,9 @@ mod rooms; mod session; mod store; -pub use client::{BaseClient, BaseClientConfig}; +pub use client::{ + hoist_and_deserialize_state_event, hoist_room_event_prev_content, BaseClient, BaseClientConfig, +}; #[cfg(feature = "encryption")] #[cfg_attr(feature = "docs", doc(cfg(encryption)))] pub use matrix_sdk_crypto as crypto; From 05eeba067ccb29acd576ce1e02705473c765d5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 26 Jul 2021 15:55:44 +0200 Subject: [PATCH 2/2] base: Add docs to the newly public hoist and deserialize method --- matrix_sdk_base/src/client.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index 7c7497ea..399b5348 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -89,8 +89,8 @@ pub struct AdditionalUnsignedData { pub prev_content: Option>, } -/// Transform state event by hoisting `prev_content` field from `unsigned` to -/// the top level. +/// Transform an `AnySyncStateEvent` by hoisting `prev_content` field from +/// `unsigned` to the top level. /// /// Due to a [bug in synapse][synapse-bug], `prev_content` often ends up in /// `unsigned` contrary to the C2S spec. Some more discussion can be found @@ -129,6 +129,16 @@ fn hoist_member_event( Ok(e) } +/// Transform an `AnySyncRoomEvent` by hoisting `prev_content` field from +/// `unsigned` to the top level. +/// +/// Due to a [bug in synapse][synapse-bug], `prev_content` often ends up in +/// `unsigned` contrary to the C2S spec. Some more discussion can be found +/// [here][discussion]. Until this is fixed in synapse or handled in Ruma, we +/// use this to hoist up `prev_content` to the top level. +/// +/// [synapse-bug]: +/// [discussion]: pub fn hoist_room_event_prev_content( event: &Raw, ) -> StdResult {