events: Add event relation conversions
This commit is contained in:
parent
84829e23dc
commit
61671f4440
@ -13,6 +13,8 @@ Breaking changes:
|
|||||||
* Rename `relation` field in some events to `relates_to`
|
* Rename `relation` field in some events to `relates_to`
|
||||||
* All events that support relations now have their own `Relation` types (the `room::relationships`
|
* All events that support relations now have their own `Relation` types (the `room::relationships`
|
||||||
module has been removed)
|
module has been removed)
|
||||||
|
* The `room::encryption` relation type can represent any kind of relation and has `From`
|
||||||
|
implementations so any other relation can be converted to it
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
|
@ -10,8 +10,11 @@ use ruma_identifiers::EventId;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
use crate::room::message::Replacement;
|
use crate::{key::verification, reaction, room::message::Replacement};
|
||||||
use crate::{room::message::InReplyTo, MessageEvent};
|
use crate::{
|
||||||
|
room::message::{self, InReplyTo},
|
||||||
|
MessageEvent,
|
||||||
|
};
|
||||||
|
|
||||||
mod relation_serde;
|
mod relation_serde;
|
||||||
|
|
||||||
@ -218,6 +221,32 @@ impl From<MegolmV1AesSha2ContentInit> for MegolmV1AesSha2Content {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<message::Relation> for Relation {
|
||||||
|
fn from(rel: message::Relation) -> Self {
|
||||||
|
match rel {
|
||||||
|
message::Relation::Reply { in_reply_to } => Self::Reply { in_reply_to },
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
message::Relation::Replacement(re) => Self::Replacement(re),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
impl From<reaction::Relation> for Relation {
|
||||||
|
fn from(rel: reaction::Relation) -> Self {
|
||||||
|
let reaction::Relation { event_id, emoji } = rel;
|
||||||
|
Self::Annotation(Annotation { event_id, key: emoji })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
impl From<verification::Relation> for Relation {
|
||||||
|
fn from(rel: verification::Relation) -> Self {
|
||||||
|
let verification::Relation { event_id } = rel;
|
||||||
|
Self::Reference(Reference { event_id })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user