ruma_events/key/verification/
done.rs
1use 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::owned_event_id;
53 use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
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
62 let json_data = json!({
63 "m.relates_to": {
64 "rel_type": "m.reference",
65 "event_id": event_id,
66 }
67 });
68
69 let content = KeyVerificationDoneEventContent { relates_to: Reference { event_id } };
70
71 assert_eq!(to_json_value(&content).unwrap(), json_data);
72 }
73
74 #[test]
75 fn deserialization() {
76 let json_data = json!({
77 "m.relates_to": {
78 "rel_type": "m.reference",
79 "event_id": "$1598361704261elfgc:localhost",
80 }
81 });
82
83 let content = from_json_value::<KeyVerificationDoneEventContent>(json_data).unwrap();
84 assert_eq!(content.relates_to.event_id, "$1598361704261elfgc:localhost");
85 }
86}