events: Use Reference instead of events:🔑:verification::Relation
This commit is contained in:
parent
e63896b916
commit
93bc8a60be
@ -36,6 +36,7 @@ Breaking changes:
|
|||||||
* Move common relation structs under `events::room::encrypted` to `events::relation` and remove
|
* Move common relation structs under `events::room::encrypted` to `events::relation` and remove
|
||||||
duplicate types
|
duplicate types
|
||||||
* Remove `events::reaction::Relation` and use `events::relation::Annotation` instead
|
* Remove `events::reaction::Relation` and use `events::relation::Annotation` instead
|
||||||
|
* Remove `events::key::verification::Relation` and use `events::relation::Reference` instead
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ use serde::{de, Deserialize};
|
|||||||
use serde_json::value::RawValue as RawJsonValue;
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
key,
|
|
||||||
room::{encrypted, redaction::SyncRoomRedactionEvent},
|
room::{encrypted, redaction::SyncRoomRedactionEvent},
|
||||||
Redact, Relations,
|
Redact, Relations,
|
||||||
};
|
};
|
||||||
@ -325,11 +324,8 @@ impl AnyMessageLikeEventContent {
|
|||||||
| Self::KeyVerificationKey(KeyVerificationKeyEventContent { relates_to, .. })
|
| Self::KeyVerificationKey(KeyVerificationKeyEventContent { relates_to, .. })
|
||||||
| Self::KeyVerificationMac(KeyVerificationMacEventContent { relates_to, .. })
|
| Self::KeyVerificationMac(KeyVerificationMacEventContent { relates_to, .. })
|
||||||
| Self::KeyVerificationDone(KeyVerificationDoneEventContent { relates_to, .. }) => {
|
| Self::KeyVerificationDone(KeyVerificationDoneEventContent { relates_to, .. }) => {
|
||||||
let key::verification::Relation { event_id } = relates_to;
|
Some(encrypted::Relation::Reference(relates_to.clone()))
|
||||||
Some(encrypted::Relation::Reference(Reference {
|
},
|
||||||
event_id: event_id.clone(),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
#[cfg(feature = "unstable-msc2677")]
|
#[cfg(feature = "unstable-msc2677")]
|
||||||
Self::Reaction(ev) => Some(encrypted::Relation::Annotation(ev.relates_to.clone())),
|
Self::Reaction(ev) => Some(encrypted::Relation::Annotation(ev.relates_to.clone())),
|
||||||
Self::RoomEncrypted(ev) => ev.relates_to.clone(),
|
Self::RoomEncrypted(ev) => ev.relates_to.clone(),
|
||||||
|
@ -7,9 +7,7 @@
|
|||||||
//!
|
//!
|
||||||
//! [MSC2241]: https://github.com/matrix-org/matrix-spec-proposals/pull/2241
|
//! [MSC2241]: https://github.com/matrix-org/matrix-spec-proposals/pull/2241
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use crate::{serde::StringEnum, PrivOwnedStr};
|
||||||
|
|
||||||
use crate::{serde::StringEnum, OwnedEventId, PrivOwnedStr};
|
|
||||||
|
|
||||||
pub mod accept;
|
pub mod accept;
|
||||||
pub mod cancel;
|
pub mod cancel;
|
||||||
@ -86,22 +84,6 @@ pub enum ShortAuthenticationString {
|
|||||||
_Custom(PrivOwnedStr),
|
_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.
|
/// A Short Authentication String (SAS) verification method.
|
||||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
#[derive(Clone, Debug, PartialEq, Eq, StringEnum)]
|
||||||
|
@ -9,10 +9,9 @@ use serde::{Deserialize, Serialize};
|
|||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation,
|
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString,
|
||||||
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.
|
/// The content of a to-device `m.key.verification.accept` event.
|
||||||
///
|
///
|
||||||
@ -52,13 +51,13 @@ pub struct KeyVerificationAcceptEventContent {
|
|||||||
|
|
||||||
/// Information about the related event.
|
/// Information about the related event.
|
||||||
#[serde(rename = "m.relates_to")]
|
#[serde(rename = "m.relates_to")]
|
||||||
pub relates_to: Relation,
|
pub relates_to: Reference,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyVerificationAcceptEventContent {
|
impl KeyVerificationAcceptEventContent {
|
||||||
/// Creates a new `ToDeviceKeyVerificationAcceptEventContent` with the given method-specific
|
/// Creates a new `ToDeviceKeyVerificationAcceptEventContent` with the given method-specific
|
||||||
/// content and relation.
|
/// content and reference.
|
||||||
pub fn new(method: AcceptMethod, relates_to: Relation) -> Self {
|
pub fn new(method: AcceptMethod, relates_to: Reference) -> Self {
|
||||||
Self { method, relates_to }
|
Self { method, relates_to }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,7 +175,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
event_id,
|
event_id,
|
||||||
events::{key::verification::Relation, ToDeviceEvent},
|
events::{relation::Reference, ToDeviceEvent},
|
||||||
serde::Base64,
|
serde::Base64,
|
||||||
user_id,
|
user_id,
|
||||||
};
|
};
|
||||||
@ -248,7 +247,7 @@ mod tests {
|
|||||||
let event_id = event_id!("$1598361704261elfgc:localhost");
|
let event_id = event_id!("$1598361704261elfgc:localhost");
|
||||||
|
|
||||||
let key_verification_accept_content = KeyVerificationAcceptEventContent {
|
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 {
|
method: AcceptMethod::SasV1(SasV1Content {
|
||||||
hash: HashAlgorithm::Sha256,
|
hash: HashAlgorithm::Sha256,
|
||||||
key_agreement_protocol: KeyAgreementProtocol::Curve25519,
|
key_agreement_protocol: KeyAgreementProtocol::Curve25519,
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
use ruma_macros::EventContent;
|
use ruma_macros::EventContent;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::Relation;
|
use crate::{events::relation::Reference, serde::StringEnum, OwnedTransactionId, PrivOwnedStr};
|
||||||
use crate::{serde::StringEnum, OwnedTransactionId, PrivOwnedStr};
|
|
||||||
|
|
||||||
/// The content of a to-device `m.key.verification.cancel` event.
|
/// The content of a to-device `m.key.verification.cancel` event.
|
||||||
///
|
///
|
||||||
@ -52,12 +51,12 @@ pub struct KeyVerificationCancelEventContent {
|
|||||||
|
|
||||||
/// Information about the related event.
|
/// Information about the related event.
|
||||||
#[serde(rename = "m.relates_to")]
|
#[serde(rename = "m.relates_to")]
|
||||||
pub relates_to: Relation,
|
pub relates_to: Reference,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyVerificationCancelEventContent {
|
impl KeyVerificationCancelEventContent {
|
||||||
/// Creates a new `KeyVerificationCancelEventContent` with the given reason, code and relation.
|
/// Creates a new `KeyVerificationCancelEventContent` with the given reason, code and reference.
|
||||||
pub fn new(reason: String, code: CancelCode, relates_to: Relation) -> Self {
|
pub fn new(reason: String, code: CancelCode, relates_to: Reference) -> Self {
|
||||||
Self { reason, code, relates_to }
|
Self { reason, code, relates_to }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
use ruma_macros::EventContent;
|
use ruma_macros::EventContent;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::Relation;
|
use crate::{events::relation::Reference, OwnedTransactionId};
|
||||||
use crate::OwnedTransactionId;
|
|
||||||
|
|
||||||
/// The content of a to-device `m.m.key.verification.done` event.
|
/// The content of a to-device `m.m.key.verification.done` event.
|
||||||
///
|
///
|
||||||
@ -37,12 +36,12 @@ impl ToDeviceKeyVerificationDoneEventContent {
|
|||||||
pub struct KeyVerificationDoneEventContent {
|
pub struct KeyVerificationDoneEventContent {
|
||||||
/// Relation signaling which verification request this event is responding to.
|
/// Relation signaling which verification request this event is responding to.
|
||||||
#[serde(rename = "m.relates_to")]
|
#[serde(rename = "m.relates_to")]
|
||||||
pub relates_to: Relation,
|
pub relates_to: Reference,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyVerificationDoneEventContent {
|
impl KeyVerificationDoneEventContent {
|
||||||
/// Creates a new `KeyVerificationDoneEventContent` with the given relation.
|
/// Creates a new `KeyVerificationDoneEventContent` with the given reference.
|
||||||
pub fn new(relates_to: Relation) -> Self {
|
pub fn new(relates_to: Reference) -> Self {
|
||||||
Self { relates_to }
|
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 serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
use super::KeyVerificationDoneEventContent;
|
use super::KeyVerificationDoneEventContent;
|
||||||
use crate::{event_id, events::key::verification::Relation};
|
use crate::{event_id, events::relation::Reference};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialization() {
|
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);
|
assert_eq!(to_json_value(&content).unwrap(), json_data);
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
use ruma_macros::EventContent;
|
use ruma_macros::EventContent;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::Relation;
|
use crate::{events::relation::Reference, serde::Base64, OwnedTransactionId};
|
||||||
use crate::{serde::Base64, OwnedTransactionId};
|
|
||||||
|
|
||||||
/// The content of a to-device `m.key.verification.key` event.
|
/// The content of a to-device `m.key.verification.key` event.
|
||||||
///
|
///
|
||||||
@ -44,12 +43,12 @@ pub struct KeyVerificationKeyEventContent {
|
|||||||
|
|
||||||
/// Information about the related event.
|
/// Information about the related event.
|
||||||
#[serde(rename = "m.relates_to")]
|
#[serde(rename = "m.relates_to")]
|
||||||
pub relates_to: Relation,
|
pub relates_to: Reference,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyVerificationKeyEventContent {
|
impl KeyVerificationKeyEventContent {
|
||||||
/// Creates a new `KeyVerificationKeyEventContent` with the given key and relation.
|
/// Creates a new `KeyVerificationKeyEventContent` with the given key and reference.
|
||||||
pub fn new(key: Base64, relates_to: Relation) -> Self {
|
pub fn new(key: Base64, relates_to: Reference) -> Self {
|
||||||
Self { key, relates_to }
|
Self { key, relates_to }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,7 @@ use std::collections::BTreeMap;
|
|||||||
use ruma_macros::EventContent;
|
use ruma_macros::EventContent;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::Relation;
|
use crate::{events::relation::Reference, serde::Base64, OwnedTransactionId};
|
||||||
use crate::{serde::Base64, OwnedTransactionId};
|
|
||||||
|
|
||||||
/// The content of a to-device `m.key.verification.` event.
|
/// The content of a to-device `m.key.verification.` event.
|
||||||
///
|
///
|
||||||
@ -62,13 +61,13 @@ pub struct KeyVerificationMacEventContent {
|
|||||||
|
|
||||||
/// Information about the related event.
|
/// Information about the related event.
|
||||||
#[serde(rename = "m.relates_to")]
|
#[serde(rename = "m.relates_to")]
|
||||||
pub relates_to: Relation,
|
pub relates_to: Reference,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyVerificationMacEventContent {
|
impl KeyVerificationMacEventContent {
|
||||||
/// Creates a new `KeyVerificationMacEventContent` with the given key ID to MAC map, key MAC and
|
/// Creates a new `KeyVerificationMacEventContent` with the given key ID to MAC map, key MAC and
|
||||||
/// relation.
|
/// reference.
|
||||||
pub fn new(mac: BTreeMap<String, Base64>, keys: Base64, relates_to: Relation) -> Self {
|
pub fn new(mac: BTreeMap<String, Base64>, keys: Base64, relates_to: Reference) -> Self {
|
||||||
Self { mac, keys, relates_to }
|
Self { mac, keys, relates_to }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
use ruma_macros::EventContent;
|
use ruma_macros::EventContent;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{Relation, VerificationMethod};
|
use super::VerificationMethod;
|
||||||
use crate::{OwnedDeviceId, OwnedTransactionId};
|
use crate::{events::relation::Reference, OwnedDeviceId, OwnedTransactionId};
|
||||||
|
|
||||||
/// The content of a to-device `m.m.key.verification.ready` event.
|
/// 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
|
/// Relation signaling which verification request this event is responding
|
||||||
/// to.
|
/// to.
|
||||||
#[serde(rename = "m.relates_to")]
|
#[serde(rename = "m.relates_to")]
|
||||||
pub relates_to: Relation,
|
pub relates_to: Reference,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyVerificationReadyEventContent {
|
impl KeyVerificationReadyEventContent {
|
||||||
/// Creates a new `KeyVerificationReadyEventContent` with the given device ID, methods and
|
/// Creates a new `KeyVerificationReadyEventContent` with the given device ID, methods and
|
||||||
/// relation.
|
/// reference.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
from_device: OwnedDeviceId,
|
from_device: OwnedDeviceId,
|
||||||
methods: Vec<VerificationMethod>,
|
methods: Vec<VerificationMethod>,
|
||||||
relates_to: Relation,
|
relates_to: Reference,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { from_device, methods, relates_to }
|
Self { from_device, methods, relates_to }
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ mod tests {
|
|||||||
use super::{KeyVerificationReadyEventContent, ToDeviceKeyVerificationReadyEventContent};
|
use super::{KeyVerificationReadyEventContent, ToDeviceKeyVerificationReadyEventContent};
|
||||||
use crate::{
|
use crate::{
|
||||||
event_id,
|
event_id,
|
||||||
events::key::verification::{Relation, VerificationMethod},
|
events::{key::verification::VerificationMethod, relation::Reference},
|
||||||
OwnedDeviceId,
|
OwnedDeviceId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ mod tests {
|
|||||||
|
|
||||||
let content = KeyVerificationReadyEventContent {
|
let content = KeyVerificationReadyEventContent {
|
||||||
from_device: device.clone(),
|
from_device: device.clone(),
|
||||||
relates_to: Relation { event_id },
|
relates_to: Reference { event_id },
|
||||||
methods: vec![VerificationMethod::SasV1],
|
methods: vec![VerificationMethod::SasV1],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,10 +9,9 @@ use serde::{Deserialize, Serialize};
|
|||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation,
|
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString,
|
||||||
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.
|
/// The content of a to-device `m.key.verification.start` event.
|
||||||
///
|
///
|
||||||
@ -64,13 +63,13 @@ pub struct KeyVerificationStartEventContent {
|
|||||||
|
|
||||||
/// Information about the related event.
|
/// Information about the related event.
|
||||||
#[serde(rename = "m.relates_to")]
|
#[serde(rename = "m.relates_to")]
|
||||||
pub relates_to: Relation,
|
pub relates_to: Reference,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyVerificationStartEventContent {
|
impl KeyVerificationStartEventContent {
|
||||||
/// Creates a new `KeyVerificationStartEventContent` with the given device ID, method and
|
/// Creates a new `KeyVerificationStartEventContent` with the given device ID, method and
|
||||||
/// relation.
|
/// reference.
|
||||||
pub fn new(from_device: OwnedDeviceId, method: StartMethod, relates_to: Relation) -> Self {
|
pub fn new(from_device: OwnedDeviceId, method: StartMethod, relates_to: Reference) -> Self {
|
||||||
Self { from_device, method, relates_to }
|
Self { from_device, method, relates_to }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,7 +217,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
event_id,
|
event_id,
|
||||||
events::{key::verification::Relation, ToDeviceEvent},
|
events::{relation::Reference, ToDeviceEvent},
|
||||||
serde::Base64,
|
serde::Base64,
|
||||||
user_id,
|
user_id,
|
||||||
};
|
};
|
||||||
@ -315,7 +314,7 @@ mod tests {
|
|||||||
|
|
||||||
let key_verification_start_content = KeyVerificationStartEventContent {
|
let key_verification_start_content = KeyVerificationStartEventContent {
|
||||||
from_device: "123".into(),
|
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(
|
method: StartMethod::SasV1(
|
||||||
SasV1ContentInit {
|
SasV1ContentInit {
|
||||||
hashes: vec![HashAlgorithm::Sha256],
|
hashes: vec![HashAlgorithm::Sha256],
|
||||||
@ -346,7 +345,7 @@ mod tests {
|
|||||||
|
|
||||||
let key_verification_start_content = KeyVerificationStartEventContent {
|
let key_verification_start_content = KeyVerificationStartEventContent {
|
||||||
from_device: "123".into(),
|
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())),
|
method: StartMethod::ReciprocateV1(ReciprocateV1Content::new(secret.clone())),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -239,6 +239,7 @@ impl BundledThread {
|
|||||||
/// [reference]: https://spec.matrix.org/v1.5/client-server-api/#reference-relations
|
/// [reference]: https://spec.matrix.org/v1.5/client-server-api/#reference-relations
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
#[serde(tag = "rel_type", rename = "m.reference")]
|
||||||
pub struct Reference {
|
pub struct Reference {
|
||||||
/// The ID of the event being referenced.
|
/// The ID of the event being referenced.
|
||||||
pub event_id: OwnedEventId,
|
pub event_id: OwnedEventId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user