diff --git a/ruma-events/src/enums.rs b/ruma-events/src/enums.rs index 8a8bf1bd..4034289c 100644 --- a/ruma-events/src/enums.rs +++ b/ruma-events/src/enums.rs @@ -49,6 +49,8 @@ event_enum! { #[cfg(feature = "unstable-pre-spec")] "m.key.verification.mac", #[cfg(feature = "unstable-pre-spec")] + "m.key.verification.done", + #[cfg(feature = "unstable-pre-spec")] "m.reaction", "m.room.encrypted", "m.room.message", diff --git a/ruma-events/src/key/verification.rs b/ruma-events/src/key/verification.rs index fc891734..3fae7315 100644 --- a/ruma-events/src/key/verification.rs +++ b/ruma-events/src/key/verification.rs @@ -19,6 +19,8 @@ use crate::room::relationships::{Reference, RelatesToJsonRepr, RelationJsonRepr} pub mod accept; pub mod cancel; +#[cfg(feature = "unstable-pre-spec")] +pub mod done; pub mod key; pub mod mac; #[cfg(feature = "unstable-pre-spec")] diff --git a/ruma-events/src/key/verification/done.rs b/ruma-events/src/key/verification/done.rs new file mode 100644 index 00000000..bcf33194 --- /dev/null +++ b/ruma-events/src/key/verification/done.rs @@ -0,0 +1,71 @@ +//! Types for the *m.key.verification.done* event. + +use ruma_events_macros::MessageEventContent; +use serde::{Deserialize, Serialize}; + +use super::Relation; +use crate::MessageEvent; + +/// Event signaling that the interactive key verification has successfully +/// concluded. +pub type DoneEvent = MessageEvent; + +/// The payload for `DoneEvent`. +#[derive(Clone, Debug, Deserialize, Serialize, MessageEventContent)] +#[ruma_event(type = "m.key.verification.done")] +pub struct DoneEventContent { + /// Relation signaling which verification request this event is responding + /// to. + #[serde(rename = "m.relates_to")] + pub relation: Relation, +} + +#[cfg(test)] +mod tests { + use matches::assert_matches; + use ruma_identifiers::event_id; + use ruma_serde::Raw; + use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; + + use super::{DoneEventContent, Relation}; + + #[test] + fn serialization() { + let event_id = event_id!("$1598361704261elfgc:localhost"); + + let json_data = json!({ + "m.relates_to": { + "rel_type": "m.reference", + "event_id": event_id, + } + }); + + let content = DoneEventContent { relation: Relation { event_id } }; + + assert_eq!(to_json_value(&content).unwrap(), json_data); + } + + #[test] + fn deserialization() { + let id = event_id!("$1598361704261elfgc:localhost"); + + let json_data = json!({ + "m.relates_to": { + "rel_type": "m.reference", + "event_id": id, + } + }); + + assert_matches!( + from_json_value::>(json_data) + .unwrap() + .deserialize() + .unwrap(), + DoneEventContent { + relation: Relation { + event_id + }, + } if event_id == id + ); + } +}