ruma_events/key/verification/
done.rs1use ruma_common::OwnedTransactionId;
6use ruma_macros::EventContent;
7use serde::{Deserialize, Serialize};
8
9use crate::relation::Reference;
10
11#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
15#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
16#[ruma_event(type = "m.key.verification.done", kind = ToDevice)]
17pub struct ToDeviceKeyVerificationDoneEventContent {
18 pub transaction_id: OwnedTransactionId,
22}
23
24impl ToDeviceKeyVerificationDoneEventContent {
25 pub fn new(transaction_id: OwnedTransactionId) -> Self {
27 Self { transaction_id }
28 }
29}
30
31#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
35#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
36#[ruma_event(type = "m.key.verification.done", kind = MessageLike)]
37pub struct KeyVerificationDoneEventContent {
38 #[serde(rename = "m.relates_to")]
40 pub relates_to: Reference,
41}
42
43impl KeyVerificationDoneEventContent {
44 pub fn new(relates_to: Reference) -> Self {
46 Self { relates_to }
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use ruma_common::{canonical_json::assert_to_canonical_json_eq, owned_event_id};
53 use serde_json::{from_value as from_json_value, json};
54
55 use super::KeyVerificationDoneEventContent;
56 use crate::relation::Reference;
57
58 #[test]
59 fn serialization() {
60 let event_id = owned_event_id!("$1598361704261elfgc:localhost");
61 let content = KeyVerificationDoneEventContent {
62 relates_to: Reference { event_id: event_id.clone() },
63 };
64
65 assert_to_canonical_json_eq!(
66 content,
67 json!({
68 "m.relates_to": {
69 "rel_type": "m.reference",
70 "event_id": event_id,
71 },
72 }),
73 );
74 }
75
76 #[test]
77 fn deserialization() {
78 let json_data = json!({
79 "m.relates_to": {
80 "rel_type": "m.reference",
81 "event_id": "$1598361704261elfgc:localhost",
82 }
83 });
84
85 let content = from_json_value::<KeyVerificationDoneEventContent>(json_data).unwrap();
86 assert_eq!(content.relates_to.event_id, "$1598361704261elfgc:localhost");
87 }
88}