ruma-events: Add support for m.key.verification.done events
This commit is contained in:
parent
ce2ab39d71
commit
3216edc137
@ -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",
|
||||
|
@ -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")]
|
||||
|
71
ruma-events/src/key/verification/done.rs
Normal file
71
ruma-events/src/key/verification/done.rs
Normal file
@ -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<DoneEventContent>;
|
||||
|
||||
/// 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::<Raw<DoneEventContent>>(json_data)
|
||||
.unwrap()
|
||||
.deserialize()
|
||||
.unwrap(),
|
||||
DoneEventContent {
|
||||
relation: Relation {
|
||||
event_id
|
||||
},
|
||||
} if event_id == id
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user