events: Use Reference instead of events:🔑:verification::Relation

This commit is contained in:
Kévin Commaille 2022-11-25 19:56:39 +01:00 committed by Kévin Commaille
parent e63896b916
commit 93bc8a60be
11 changed files with 45 additions and 71 deletions

View File

@ -36,6 +36,7 @@ Breaking changes:
* Move common relation structs under `events::room::encrypted` to `events::relation` and remove
duplicate types
* Remove `events::reaction::Relation` and use `events::relation::Annotation` instead
* Remove `events::key::verification::Relation` and use `events::relation::Reference` instead
Improvements:

View File

@ -3,7 +3,6 @@ use serde::{de, Deserialize};
use serde_json::value::RawValue as RawJsonValue;
use super::{
key,
room::{encrypted, redaction::SyncRoomRedactionEvent},
Redact, Relations,
};
@ -325,11 +324,8 @@ impl AnyMessageLikeEventContent {
| Self::KeyVerificationKey(KeyVerificationKeyEventContent { relates_to, .. })
| Self::KeyVerificationMac(KeyVerificationMacEventContent { relates_to, .. })
| Self::KeyVerificationDone(KeyVerificationDoneEventContent { relates_to, .. }) => {
let key::verification::Relation { event_id } = relates_to;
Some(encrypted::Relation::Reference(Reference {
event_id: event_id.clone(),
}))
}
Some(encrypted::Relation::Reference(relates_to.clone()))
},
#[cfg(feature = "unstable-msc2677")]
Self::Reaction(ev) => Some(encrypted::Relation::Annotation(ev.relates_to.clone())),
Self::RoomEncrypted(ev) => ev.relates_to.clone(),

View File

@ -7,9 +7,7 @@
//!
//! [MSC2241]: https://github.com/matrix-org/matrix-spec-proposals/pull/2241
use serde::{Deserialize, Serialize};
use crate::{serde::StringEnum, OwnedEventId, PrivOwnedStr};
use crate::{serde::StringEnum, PrivOwnedStr};
pub mod accept;
pub mod cancel;
@ -86,22 +84,6 @@ pub enum ShortAuthenticationString {
_Custom(PrivOwnedStr),
}
/// A relation which associates an `m.key.verification.request` with another key verification event.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "rel_type", rename = "m.reference")]
pub struct Relation {
/// The event ID of a related `m.key.verification.request`.
pub event_id: OwnedEventId,
}
impl Relation {
/// Creates a new `Relation` with the given event ID.
pub fn new(event_id: OwnedEventId) -> Self {
Self { event_id }
}
}
/// A Short Authentication String (SAS) verification method.
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]

View File

@ -9,10 +9,9 @@ use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
use super::{
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation,
ShortAuthenticationString,
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString,
};
use crate::{serde::Base64, OwnedTransactionId};
use crate::{events::relation::Reference, serde::Base64, OwnedTransactionId};
/// The content of a to-device `m.key.verification.accept` event.
///
@ -52,13 +51,13 @@ pub struct KeyVerificationAcceptEventContent {
/// Information about the related event.
#[serde(rename = "m.relates_to")]
pub relates_to: Relation,
pub relates_to: Reference,
}
impl KeyVerificationAcceptEventContent {
/// Creates a new `ToDeviceKeyVerificationAcceptEventContent` with the given method-specific
/// content and relation.
pub fn new(method: AcceptMethod, relates_to: Relation) -> Self {
/// content and reference.
pub fn new(method: AcceptMethod, relates_to: Reference) -> Self {
Self { method, relates_to }
}
}
@ -176,7 +175,7 @@ mod tests {
};
use crate::{
event_id,
events::{key::verification::Relation, ToDeviceEvent},
events::{relation::Reference, ToDeviceEvent},
serde::Base64,
user_id,
};
@ -248,7 +247,7 @@ mod tests {
let event_id = event_id!("$1598361704261elfgc:localhost");
let key_verification_accept_content = KeyVerificationAcceptEventContent {
relates_to: Relation { event_id: event_id.to_owned() },
relates_to: Reference { event_id: event_id.to_owned() },
method: AcceptMethod::SasV1(SasV1Content {
hash: HashAlgorithm::Sha256,
key_agreement_protocol: KeyAgreementProtocol::Curve25519,

View File

@ -5,8 +5,7 @@
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::Relation;
use crate::{serde::StringEnum, OwnedTransactionId, PrivOwnedStr};
use crate::{events::relation::Reference, serde::StringEnum, OwnedTransactionId, PrivOwnedStr};
/// The content of a to-device `m.key.verification.cancel` event.
///
@ -52,12 +51,12 @@ pub struct KeyVerificationCancelEventContent {
/// Information about the related event.
#[serde(rename = "m.relates_to")]
pub relates_to: Relation,
pub relates_to: Reference,
}
impl KeyVerificationCancelEventContent {
/// Creates a new `KeyVerificationCancelEventContent` with the given reason, code and relation.
pub fn new(reason: String, code: CancelCode, relates_to: Relation) -> Self {
/// Creates a new `KeyVerificationCancelEventContent` with the given reason, code and reference.
pub fn new(reason: String, code: CancelCode, relates_to: Reference) -> Self {
Self { reason, code, relates_to }
}
}

View File

@ -5,8 +5,7 @@
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::Relation;
use crate::OwnedTransactionId;
use crate::{events::relation::Reference, OwnedTransactionId};
/// The content of a to-device `m.m.key.verification.done` event.
///
@ -37,12 +36,12 @@ impl ToDeviceKeyVerificationDoneEventContent {
pub struct KeyVerificationDoneEventContent {
/// Relation signaling which verification request this event is responding to.
#[serde(rename = "m.relates_to")]
pub relates_to: Relation,
pub relates_to: Reference,
}
impl KeyVerificationDoneEventContent {
/// Creates a new `KeyVerificationDoneEventContent` with the given relation.
pub fn new(relates_to: Relation) -> Self {
/// Creates a new `KeyVerificationDoneEventContent` with the given reference.
pub fn new(relates_to: Reference) -> Self {
Self { relates_to }
}
}
@ -52,7 +51,7 @@ mod tests {
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
use super::KeyVerificationDoneEventContent;
use crate::{event_id, events::key::verification::Relation};
use crate::{event_id, events::relation::Reference};
#[test]
fn serialization() {
@ -65,7 +64,7 @@ mod tests {
}
});
let content = KeyVerificationDoneEventContent { relates_to: Relation { event_id } };
let content = KeyVerificationDoneEventContent { relates_to: Reference { event_id } };
assert_eq!(to_json_value(&content).unwrap(), json_data);
}

View File

@ -5,8 +5,7 @@
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::Relation;
use crate::{serde::Base64, OwnedTransactionId};
use crate::{events::relation::Reference, serde::Base64, OwnedTransactionId};
/// The content of a to-device `m.key.verification.key` event.
///
@ -44,12 +43,12 @@ pub struct KeyVerificationKeyEventContent {
/// Information about the related event.
#[serde(rename = "m.relates_to")]
pub relates_to: Relation,
pub relates_to: Reference,
}
impl KeyVerificationKeyEventContent {
/// Creates a new `KeyVerificationKeyEventContent` with the given key and relation.
pub fn new(key: Base64, relates_to: Relation) -> Self {
/// Creates a new `KeyVerificationKeyEventContent` with the given key and reference.
pub fn new(key: Base64, relates_to: Reference) -> Self {
Self { key, relates_to }
}
}

View File

@ -7,8 +7,7 @@ use std::collections::BTreeMap;
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::Relation;
use crate::{serde::Base64, OwnedTransactionId};
use crate::{events::relation::Reference, serde::Base64, OwnedTransactionId};
/// The content of a to-device `m.key.verification.` event.
///
@ -62,13 +61,13 @@ pub struct KeyVerificationMacEventContent {
/// Information about the related event.
#[serde(rename = "m.relates_to")]
pub relates_to: Relation,
pub relates_to: Reference,
}
impl KeyVerificationMacEventContent {
/// Creates a new `KeyVerificationMacEventContent` with the given key ID to MAC map, key MAC and
/// relation.
pub fn new(mac: BTreeMap<String, Base64>, keys: Base64, relates_to: Relation) -> Self {
/// reference.
pub fn new(mac: BTreeMap<String, Base64>, keys: Base64, relates_to: Reference) -> Self {
Self { mac, keys, relates_to }
}
}

View File

@ -5,8 +5,8 @@
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use super::{Relation, VerificationMethod};
use crate::{OwnedDeviceId, OwnedTransactionId};
use super::VerificationMethod;
use crate::{events::relation::Reference, OwnedDeviceId, OwnedTransactionId};
/// The content of a to-device `m.m.key.verification.ready` event.
///
@ -57,16 +57,16 @@ pub struct KeyVerificationReadyEventContent {
/// Relation signaling which verification request this event is responding
/// to.
#[serde(rename = "m.relates_to")]
pub relates_to: Relation,
pub relates_to: Reference,
}
impl KeyVerificationReadyEventContent {
/// Creates a new `KeyVerificationReadyEventContent` with the given device ID, methods and
/// relation.
/// reference.
pub fn new(
from_device: OwnedDeviceId,
methods: Vec<VerificationMethod>,
relates_to: Relation,
relates_to: Reference,
) -> Self {
Self { from_device, methods, relates_to }
}
@ -79,7 +79,7 @@ mod tests {
use super::{KeyVerificationReadyEventContent, ToDeviceKeyVerificationReadyEventContent};
use crate::{
event_id,
events::key::verification::{Relation, VerificationMethod},
events::{key::verification::VerificationMethod, relation::Reference},
OwnedDeviceId,
};
@ -99,7 +99,7 @@ mod tests {
let content = KeyVerificationReadyEventContent {
from_device: device.clone(),
relates_to: Relation { event_id },
relates_to: Reference { event_id },
methods: vec![VerificationMethod::SasV1],
};

View File

@ -9,10 +9,9 @@ use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
use super::{
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation,
ShortAuthenticationString,
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString,
};
use crate::{serde::Base64, OwnedDeviceId, OwnedTransactionId};
use crate::{events::relation::Reference, serde::Base64, OwnedDeviceId, OwnedTransactionId};
/// The content of a to-device `m.key.verification.start` event.
///
@ -64,13 +63,13 @@ pub struct KeyVerificationStartEventContent {
/// Information about the related event.
#[serde(rename = "m.relates_to")]
pub relates_to: Relation,
pub relates_to: Reference,
}
impl KeyVerificationStartEventContent {
/// Creates a new `KeyVerificationStartEventContent` with the given device ID, method and
/// relation.
pub fn new(from_device: OwnedDeviceId, method: StartMethod, relates_to: Relation) -> Self {
/// reference.
pub fn new(from_device: OwnedDeviceId, method: StartMethod, relates_to: Reference) -> Self {
Self { from_device, method, relates_to }
}
}
@ -218,7 +217,7 @@ mod tests {
};
use crate::{
event_id,
events::{key::verification::Relation, ToDeviceEvent},
events::{relation::Reference, ToDeviceEvent},
serde::Base64,
user_id,
};
@ -315,7 +314,7 @@ mod tests {
let key_verification_start_content = KeyVerificationStartEventContent {
from_device: "123".into(),
relates_to: Relation { event_id: event_id.to_owned() },
relates_to: Reference { event_id: event_id.to_owned() },
method: StartMethod::SasV1(
SasV1ContentInit {
hashes: vec![HashAlgorithm::Sha256],
@ -346,7 +345,7 @@ mod tests {
let key_verification_start_content = KeyVerificationStartEventContent {
from_device: "123".into(),
relates_to: Relation { event_id: event_id.to_owned() },
relates_to: Reference { event_id: event_id.to_owned() },
method: StartMethod::ReciprocateV1(ReciprocateV1Content::new(secret.clone())),
};

View File

@ -239,6 +239,7 @@ impl BundledThread {
/// [reference]: https://spec.matrix.org/v1.5/client-server-api/#reference-relations
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "rel_type", rename = "m.reference")]
pub struct Reference {
/// The ID of the event being referenced.
pub event_id: OwnedEventId,