Merge branch 'hoist-deserialize-fix'
This commit is contained in:
commit
3d734a120d
3 changed files with 21 additions and 8 deletions
|
@ -14,6 +14,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
use std::ops::Deref;
|
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 matrix_sdk_common::async_trait;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::r0::push::get_notifications::Notification,
|
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| {
|
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))
|
Some((e, d))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -101,7 +102,7 @@ impl Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (raw_event, event) in room_info.timeline.events.iter().filter_map(|e| {
|
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))
|
Some((&e.event, d))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -121,7 +122,7 @@ impl Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (raw_event, event) in room_info.state.events.iter().filter_map(|e| {
|
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))
|
Some((e, d))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -131,7 +132,7 @@ impl Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (raw_event, event) in room_info.timeline.events.iter().filter_map(|e| {
|
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))
|
Some((&e.event, d))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -89,8 +89,8 @@ pub struct AdditionalUnsignedData {
|
||||||
pub prev_content: Option<Raw<MemberEventContent>>,
|
pub prev_content: Option<Raw<MemberEventContent>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transform state event by hoisting `prev_content` field from `unsigned` to
|
/// Transform an `AnySyncStateEvent` by hoisting `prev_content` field from
|
||||||
/// the top level.
|
/// `unsigned` to the top level.
|
||||||
///
|
///
|
||||||
/// Due to a [bug in synapse][synapse-bug], `prev_content` often ends up in
|
/// 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
|
/// `unsigned` contrary to the C2S spec. Some more discussion can be found
|
||||||
|
@ -129,7 +129,17 @@ fn hoist_member_event(
|
||||||
Ok(e)
|
Ok(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hoist_room_event_prev_content(
|
/// 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]: <https://github.com/matrix-org/matrix-doc/issues/684#issuecomment-641182668>
|
||||||
|
/// [discussion]: <https://github.com/matrix-org/matrix-doc/issues/684#issuecomment-641182668>
|
||||||
|
pub fn hoist_room_event_prev_content(
|
||||||
event: &Raw<AnySyncRoomEvent>,
|
event: &Raw<AnySyncRoomEvent>,
|
||||||
) -> StdResult<AnySyncRoomEvent, serde_json::Error> {
|
) -> StdResult<AnySyncRoomEvent, serde_json::Error> {
|
||||||
let prev_content = event
|
let prev_content = event
|
||||||
|
|
|
@ -50,7 +50,9 @@ mod rooms;
|
||||||
mod session;
|
mod session;
|
||||||
mod store;
|
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(feature = "encryption")]
|
||||||
#[cfg_attr(feature = "docs", doc(cfg(encryption)))]
|
#[cfg_attr(feature = "docs", doc(cfg(encryption)))]
|
||||||
pub use matrix_sdk_crypto as crypto;
|
pub use matrix_sdk_crypto as crypto;
|
||||||
|
|
Loading…
Reference in a new issue