ruma-events: Add support for m.key.verification.done events

This commit is contained in:
Damir Jelić 2020-12-04 15:32:36 +01:00 committed by Jonas Platte
parent ce2ab39d71
commit 3216edc137
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
3 changed files with 75 additions and 0 deletions

View File

@ -49,6 +49,8 @@ event_enum! {
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
"m.key.verification.mac", "m.key.verification.mac",
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
"m.key.verification.done",
#[cfg(feature = "unstable-pre-spec")]
"m.reaction", "m.reaction",
"m.room.encrypted", "m.room.encrypted",
"m.room.message", "m.room.message",

View File

@ -19,6 +19,8 @@ use crate::room::relationships::{Reference, RelatesToJsonRepr, RelationJsonRepr}
pub mod accept; pub mod accept;
pub mod cancel; pub mod cancel;
#[cfg(feature = "unstable-pre-spec")]
pub mod done;
pub mod key; pub mod key;
pub mod mac; pub mod mac;
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]

View 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
);
}
}