events: Fix new_content serialization in the plain-text part of m.encrypted
This commit is contained in:
parent
3101be1f99
commit
6236b024fd
@ -10,7 +10,7 @@ use ruma_identifiers::EventId;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use crate::{key::verification, reaction, room::message::Replacement};
|
use crate::{key::verification, reaction};
|
||||||
use crate::{
|
use crate::{
|
||||||
room::message::{self, InReplyTo},
|
room::message::{self, InReplyTo},
|
||||||
MessageEvent,
|
MessageEvent,
|
||||||
@ -95,6 +95,19 @@ pub enum Relation {
|
|||||||
Annotation(Annotation),
|
Annotation(Annotation),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The event this relation belongs to replaces another event.
|
||||||
|
///
|
||||||
|
/// In contrast to [`message::Replacement`], this struct doesn't store the new content, since that
|
||||||
|
/// is part of the encrypted payload for `m.encrypted` events.
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
pub struct Replacement {
|
||||||
|
/// The ID of the event being replacing.
|
||||||
|
pub event_id: EventId,
|
||||||
|
}
|
||||||
|
|
||||||
/// A reference to another event.
|
/// A reference to another event.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
@ -221,12 +234,15 @@ impl From<MegolmV1AesSha2ContentInit> for MegolmV1AesSha2Content {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Remove on next breaking change release
|
||||||
impl From<message::Relation> for Relation {
|
impl From<message::Relation> for Relation {
|
||||||
fn from(rel: message::Relation) -> Self {
|
fn from(rel: message::Relation) -> Self {
|
||||||
match rel {
|
match rel {
|
||||||
message::Relation::Reply { in_reply_to } => Self::Reply { in_reply_to },
|
message::Relation::Reply { in_reply_to } => Self::Reply { in_reply_to },
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
message::Relation::Replacement(re) => Self::Replacement(re),
|
message::Relation::Replacement(re) => {
|
||||||
|
Self::Replacement(Replacement { event_id: re.event_id })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
#[cfg(feature = "unstable-pre-spec")]
|
|
||||||
use ruma_identifiers::EventId;
|
|
||||||
use serde::{ser::SerializeStruct as _, Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{ser::SerializeStruct as _, Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use super::{Annotation, Reference, Replacement};
|
use super::{Annotation, Reference, Replacement};
|
||||||
use super::{InReplyTo, Relation};
|
use super::{InReplyTo, Relation};
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
|
||||||
use crate::room::message::MessageEventContent;
|
|
||||||
|
|
||||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Relation>, D::Error>
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Relation>, D::Error>
|
||||||
where
|
where
|
||||||
@ -22,9 +18,8 @@ where
|
|||||||
let relation = match relation {
|
let relation = match relation {
|
||||||
RelationJsonRepr::Annotation(a) => Relation::Annotation(a),
|
RelationJsonRepr::Annotation(a) => Relation::Annotation(a),
|
||||||
RelationJsonRepr::Reference(r) => Relation::Reference(r),
|
RelationJsonRepr::Reference(r) => Relation::Reference(r),
|
||||||
RelationJsonRepr::Replacement(ReplacementJsonRepr { event_id }) => {
|
RelationJsonRepr::Replacement(Replacement { event_id }) => {
|
||||||
let new_content = ev.new_content?;
|
Relation::Replacement(Replacement { event_id })
|
||||||
Relation::Replacement(Replacement { event_id, new_content })
|
|
||||||
}
|
}
|
||||||
// FIXME: Maybe we should log this, though at this point we don't even have access
|
// FIXME: Maybe we should log this, though at this point we don't even have access
|
||||||
// to the rel_type of the unknown relation.
|
// to the rel_type of the unknown relation.
|
||||||
@ -64,17 +59,12 @@ where
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
Relation::Replacement(Replacement { event_id, new_content }) => {
|
Relation::Replacement(r) => EventWithRelatesToJsonRepr {
|
||||||
EventWithRelatesToJsonRepr {
|
relates_to: RelatesToJsonRepr {
|
||||||
relates_to: RelatesToJsonRepr {
|
relation: Some(RelationJsonRepr::Replacement(r.clone())),
|
||||||
relation: Some(RelationJsonRepr::Replacement(ReplacementJsonRepr {
|
..Default::default()
|
||||||
event_id: event_id.clone(),
|
},
|
||||||
})),
|
},
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
new_content: Some(new_content.clone()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Relation::Reply { in_reply_to } => EventWithRelatesToJsonRepr::new(RelatesToJsonRepr {
|
Relation::Reply { in_reply_to } => EventWithRelatesToJsonRepr::new(RelatesToJsonRepr {
|
||||||
in_reply_to: Some(in_reply_to.clone()),
|
in_reply_to: Some(in_reply_to.clone()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -88,19 +78,11 @@ where
|
|||||||
struct EventWithRelatesToJsonRepr {
|
struct EventWithRelatesToJsonRepr {
|
||||||
#[serde(rename = "m.relates_to", default, skip_serializing_if = "RelatesToJsonRepr::is_empty")]
|
#[serde(rename = "m.relates_to", default, skip_serializing_if = "RelatesToJsonRepr::is_empty")]
|
||||||
relates_to: RelatesToJsonRepr,
|
relates_to: RelatesToJsonRepr,
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
|
||||||
#[serde(rename = "m.new_content", skip_serializing_if = "Option::is_none")]
|
|
||||||
new_content: Option<Box<MessageEventContent>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventWithRelatesToJsonRepr {
|
impl EventWithRelatesToJsonRepr {
|
||||||
fn new(relates_to: RelatesToJsonRepr) -> Self {
|
fn new(relates_to: RelatesToJsonRepr) -> Self {
|
||||||
Self {
|
Self { relates_to }
|
||||||
relates_to,
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
|
||||||
new_content: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +127,7 @@ enum RelationJsonRepr {
|
|||||||
|
|
||||||
/// An event that replaces another event.
|
/// An event that replaces another event.
|
||||||
#[serde(rename = "m.replace")]
|
#[serde(rename = "m.replace")]
|
||||||
Replacement(ReplacementJsonRepr),
|
Replacement(Replacement),
|
||||||
|
|
||||||
/// An unknown relation type.
|
/// An unknown relation type.
|
||||||
///
|
///
|
||||||
@ -154,9 +136,3 @@ enum RelationJsonRepr {
|
|||||||
#[serde(other)]
|
#[serde(other)]
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Serialize)]
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
|
||||||
struct ReplacementJsonRepr {
|
|
||||||
event_id: EventId,
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user