events: Move new verification events out of unstable-pre-spec

… since they were stabilized with v1.1.
This commit is contained in:
Jonas Platte 2022-01-31 20:10:08 +01:00
parent 90fe9edc32
commit 89ae41166d
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
13 changed files with 41 additions and 137 deletions

View File

@ -5,7 +5,7 @@ use serde::{de, Deserialize, Serialize};
use serde_json::value::RawValue as RawJsonValue; use serde_json::value::RawValue as RawJsonValue;
use crate::{ use crate::{
from_raw_json_value, from_raw_json_value, key,
room::{encrypted, message, redaction::SyncRoomRedactionEvent}, room::{encrypted, message, redaction::SyncRoomRedactionEvent},
Redact, UnsignedDeHelper, Redact, UnsignedDeHelper,
}; };
@ -36,19 +36,12 @@ event_enum! {
"m.call.invite", "m.call.invite",
"m.call.hangup", "m.call.hangup",
"m.call.candidates", "m.call.candidates",
#[cfg(feature = "unstable-pre-spec")]
"m.key.verification.ready", "m.key.verification.ready",
#[cfg(feature = "unstable-pre-spec")]
"m.key.verification.start", "m.key.verification.start",
#[cfg(feature = "unstable-pre-spec")]
"m.key.verification.cancel", "m.key.verification.cancel",
#[cfg(feature = "unstable-pre-spec")]
"m.key.verification.accept", "m.key.verification.accept",
#[cfg(feature = "unstable-pre-spec")]
"m.key.verification.key", "m.key.verification.key",
#[cfg(feature = "unstable-pre-spec")]
"m.key.verification.mac", "m.key.verification.mac",
#[cfg(feature = "unstable-pre-spec")]
"m.key.verification.done", "m.key.verification.done",
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
"m.reaction", "m.reaction",
@ -93,14 +86,12 @@ event_enum! {
"m.room_key_request", "m.room_key_request",
"m.forwarded_room_key", "m.forwarded_room_key",
"m.key.verification.request", "m.key.verification.request",
#[cfg(feature = "unstable-pre-spec")]
"m.key.verification.ready", "m.key.verification.ready",
"m.key.verification.start", "m.key.verification.start",
"m.key.verification.cancel", "m.key.verification.cancel",
"m.key.verification.accept", "m.key.verification.accept",
"m.key.verification.key", "m.key.verification.key",
"m.key.verification.mac", "m.key.verification.mac",
#[cfg(feature = "unstable-pre-spec")]
"m.key.verification.done", "m.key.verification.done",
"m.room.encrypted", "m.room.encrypted",
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
@ -331,23 +322,14 @@ impl AnyMessageEventContent {
/// This is a helper function intended for encryption. There should not be a reason to access /// This is a helper function intended for encryption. There should not be a reason to access
/// `m.relates_to` without first destructuring an `AnyMessageEventContent` otherwise. /// `m.relates_to` without first destructuring an `AnyMessageEventContent` otherwise.
pub fn relation(&self) -> Option<encrypted::Relation> { pub fn relation(&self) -> Option<encrypted::Relation> {
#[cfg(feature = "unstable-pre-spec")] use crate::key::verification::{
use crate::{ accept::KeyVerificationAcceptEventContent, cancel::KeyVerificationCancelEventContent,
key::{ done::KeyVerificationDoneEventContent, key::KeyVerificationKeyEventContent,
self, mac::KeyVerificationMacEventContent, ready::KeyVerificationReadyEventContent,
verification::{ start::KeyVerificationStartEventContent,
accept::KeyVerificationAcceptEventContent,
cancel::KeyVerificationCancelEventContent,
done::KeyVerificationDoneEventContent, key::KeyVerificationKeyEventContent,
mac::KeyVerificationMacEventContent, ready::KeyVerificationReadyEventContent,
start::KeyVerificationStartEventContent,
},
},
reaction,
}; };
match self { match self {
#[cfg(feature = "unstable-pre-spec")]
#[rustfmt::skip] #[rustfmt::skip]
Self::KeyVerificationReady(KeyVerificationReadyEventContent { relates_to, .. }) Self::KeyVerificationReady(KeyVerificationReadyEventContent { relates_to, .. })
| Self::KeyVerificationStart(KeyVerificationStartEventContent { relates_to, .. }) | Self::KeyVerificationStart(KeyVerificationStartEventContent { relates_to, .. })
@ -363,6 +345,8 @@ impl AnyMessageEventContent {
} }
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
Self::Reaction(ev) => { Self::Reaction(ev) => {
use crate::reaction;
let reaction::Relation { event_id, emoji } = &ev.relates_to; let reaction::Relation { event_id, emoji } = &ev.relates_to;
Some(encrypted::Relation::Annotation(encrypted::Annotation { Some(encrypted::Relation::Annotation(encrypted::Annotation {
event_id: event_id.clone(), event_id: event_id.clone(),

View File

@ -6,21 +6,18 @@
//! [on GitHub][github-matrix-doc-2214]. //! [on GitHub][github-matrix-doc-2214].
//! //!
//! [github-matrix-doc-2214]: https://github.com/matrix-org/matrix-doc/pull/2241 //! [github-matrix-doc-2214]: https://github.com/matrix-org/matrix-doc/pull/2241
#[cfg(feature = "unstable-pre-spec")]
use ruma_identifiers::EventId; use ruma_identifiers::EventId;
use ruma_serde::StringEnum; use ruma_serde::StringEnum;
#[cfg(feature = "unstable-pre-spec")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::PrivOwnedStr; use crate::PrivOwnedStr;
pub mod accept; pub mod accept;
pub mod cancel; pub mod cancel;
#[cfg(feature = "unstable-pre-spec")]
pub mod done; pub mod done;
pub mod key; pub mod key;
pub mod mac; pub mod mac;
#[cfg(feature = "unstable-pre-spec")]
pub mod ready; pub mod ready;
pub mod request; pub mod request;
pub mod start; pub mod start;
@ -124,7 +121,6 @@ impl ShortAuthenticationString {
/// A relation which associates an `m.key.verification.request` with another key verification event. /// A relation which associates an `m.key.verification.request` with another key verification event.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg(feature = "unstable-pre-spec")]
#[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")] #[serde(tag = "rel_type", rename = "m.reference")]
pub struct Relation { pub struct Relation {
@ -132,7 +128,6 @@ pub struct Relation {
pub event_id: Box<EventId>, pub event_id: Box<EventId>,
} }
#[cfg(feature = "unstable-pre-spec")]
impl Relation { impl Relation {
/// Creates a new `Relation` with the given event ID. /// Creates a new `Relation` with the given event ID.
pub fn new(event_id: Box<EventId>) -> Self { pub fn new(event_id: Box<EventId>) -> Self {
@ -152,17 +147,14 @@ pub enum VerificationMethod {
SasV1, SasV1,
/// The `m.qr_code.scan.v1` verification method. /// The `m.qr_code.scan.v1` verification method.
#[cfg(feature = "unstable-pre-spec")]
#[ruma_enum(rename = "m.qr_code.scan.v1")] #[ruma_enum(rename = "m.qr_code.scan.v1")]
QrCodeScanV1, QrCodeScanV1,
/// The `m.qr_code.show.v1` verification method. /// The `m.qr_code.show.v1` verification method.
#[cfg(feature = "unstable-pre-spec")]
#[ruma_enum(rename = "m.qr_code.show.v1")] #[ruma_enum(rename = "m.qr_code.show.v1")]
QrCodeShowV1, QrCodeShowV1,
/// The `m.reciprocate.v1` verification method. /// The `m.reciprocate.v1` verification method.
#[cfg(feature = "unstable-pre-spec")]
#[ruma_enum(rename = "m.reciprocate.v1")] #[ruma_enum(rename = "m.reciprocate.v1")]
ReciprocateV1, ReciprocateV1,

View File

@ -10,10 +10,9 @@ use ruma_serde::Base64;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
#[cfg(feature = "unstable-pre-spec")]
use super::Relation;
use super::{ use super::{
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString, HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation,
ShortAuthenticationString,
}; };
/// The content of a to-device `m.key.verification.accept` event. /// The content of a to-device `m.key.verification.accept` event.
@ -46,7 +45,6 @@ impl ToDeviceKeyVerificationAcceptEventContent {
/// Accepts a previously sent `m.key.verification.start` message. /// Accepts a previously sent `m.key.verification.start` message.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[ruma_event(type = "m.key.verification.accept", kind = Message)] #[ruma_event(type = "m.key.verification.accept", kind = Message)]
#[cfg(feature = "unstable-pre-spec")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct KeyVerificationAcceptEventContent { pub struct KeyVerificationAcceptEventContent {
/// The method specific content. /// The method specific content.
@ -58,7 +56,6 @@ pub struct KeyVerificationAcceptEventContent {
pub relates_to: Relation, pub relates_to: Relation,
} }
#[cfg(feature = "unstable-pre-spec")]
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 relation.
@ -169,23 +166,18 @@ mod tests {
use std::collections::BTreeMap; use std::collections::BTreeMap;
use matches::assert_matches; use matches::assert_matches;
#[cfg(feature = "unstable-pre-spec")] use ruma_identifiers::{event_id, user_id};
use ruma_identifiers::event_id;
use ruma_identifiers::user_id;
use ruma_serde::Base64; use ruma_serde::Base64;
use serde_json::{ use serde_json::{
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue, from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
}; };
#[cfg(feature = "unstable-pre-spec")]
use super::KeyVerificationAcceptEventContent;
use super::{ use super::{
AcceptMethod, HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, SasV1Content, AcceptMethod, HashAlgorithm, KeyAgreementProtocol, KeyVerificationAcceptEventContent,
ShortAuthenticationString, ToDeviceKeyVerificationAcceptEventContent, _CustomContent, MessageAuthenticationCode, SasV1Content, ShortAuthenticationString,
ToDeviceKeyVerificationAcceptEventContent, _CustomContent,
}; };
#[cfg(feature = "unstable-pre-spec")] use crate::{key::verification::Relation, ToDeviceEvent};
use crate::key::verification::Relation;
use crate::ToDeviceEvent;
#[test] #[test]
fn serialization() { fn serialization() {
@ -250,7 +242,6 @@ mod tests {
} }
#[test] #[test]
#[cfg(feature = "unstable-pre-spec")]
fn in_room_serialization() { fn in_room_serialization() {
let event_id = event_id!("$1598361704261elfgc:localhost"); let event_id = event_id!("$1598361704261elfgc:localhost");
@ -384,7 +375,6 @@ mod tests {
} }
#[test] #[test]
#[cfg(feature = "unstable-pre-spec")]
fn in_room_deserialization() { fn in_room_deserialization() {
let id = event_id!("$1598361704261elfgc:localhost"); let id = event_id!("$1598361704261elfgc:localhost");

View File

@ -7,10 +7,8 @@ use ruma_identifiers::TransactionId;
use ruma_serde::StringEnum; use ruma_serde::StringEnum;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::PrivOwnedStr;
#[cfg(feature = "unstable-pre-spec")]
use super::Relation; use super::Relation;
use crate::PrivOwnedStr;
/// The content of a to-device `m.key.verification.cancel` event. /// The content of a to-device `m.key.verification.cancel` event.
/// ///
@ -43,7 +41,6 @@ impl ToDeviceKeyVerificationCancelEventContent {
/// ///
/// Cancels a key verification process/request. /// Cancels a key verification process/request.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg(feature = "unstable-pre-spec")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.key.verification.cancel", kind = Message)] #[ruma_event(type = "m.key.verification.cancel", kind = Message)]
pub struct KeyVerificationCancelEventContent { pub struct KeyVerificationCancelEventContent {
@ -60,7 +57,6 @@ pub struct KeyVerificationCancelEventContent {
pub relates_to: Relation, pub relates_to: Relation,
} }
#[cfg(feature = "unstable-pre-spec")]
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 relation.
pub fn new(reason: String, code: CancelCode, relates_to: Relation) -> Self { pub fn new(reason: String, code: CancelCode, relates_to: Relation) -> Self {

View File

@ -7,7 +7,6 @@ use ruma_identifiers::TransactionId;
use ruma_serde::Base64; use ruma_serde::Base64;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "unstable-pre-spec")]
use super::Relation; use super::Relation;
/// The content of a to-device `m.key.verification.key` event. /// The content of a to-device `m.key.verification.key` event.
@ -38,7 +37,6 @@ impl ToDeviceKeyVerificationKeyEventContent {
/// ///
/// Sends the ephemeral public key for a device to the partner device. /// Sends the ephemeral public key for a device to the partner device.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg(feature = "unstable-pre-spec")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.key.verification.key", kind = Message)] #[ruma_event(type = "m.key.verification.key", kind = Message)]
pub struct KeyVerificationKeyEventContent { pub struct KeyVerificationKeyEventContent {
@ -50,7 +48,6 @@ pub struct KeyVerificationKeyEventContent {
pub relates_to: Relation, pub relates_to: Relation,
} }
#[cfg(feature = "unstable-pre-spec")]
impl KeyVerificationKeyEventContent { impl KeyVerificationKeyEventContent {
/// Creates a new `KeyVerificationKeyEventContent` with the given key and relation. /// Creates a new `KeyVerificationKeyEventContent` with the given key and relation.
pub fn new(key: Base64, relates_to: Relation) -> Self { pub fn new(key: Base64, relates_to: Relation) -> Self {

View File

@ -9,7 +9,6 @@ use ruma_identifiers::TransactionId;
use ruma_serde::Base64; use ruma_serde::Base64;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "unstable-pre-spec")]
use super::Relation; use super::Relation;
/// The content of a to-device `m.key.verification.` event. /// The content of a to-device `m.key.verification.` event.
@ -50,7 +49,6 @@ impl ToDeviceKeyVerificationMacEventContent {
/// ///
/// Sends the MAC of a device's key to the partner device. /// Sends the MAC of a device's key to the partner device.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg(feature = "unstable-pre-spec")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.key.verification.mac", kind = Message)] #[ruma_event(type = "m.key.verification.mac", kind = Message)]
pub struct KeyVerificationMacEventContent { pub struct KeyVerificationMacEventContent {
@ -68,7 +66,6 @@ pub struct KeyVerificationMacEventContent {
pub relates_to: Relation, pub relates_to: Relation,
} }
#[cfg(feature = "unstable-pre-spec")]
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. /// relation.

View File

@ -6,15 +6,13 @@ use std::collections::BTreeMap;
use ruma_events_macros::EventContent; use ruma_events_macros::EventContent;
use ruma_identifiers::{DeviceId, TransactionId}; use ruma_identifiers::{DeviceId, TransactionId};
#[cfg(feature = "unstable-pre-spec")]
use ruma_serde::Base64; use ruma_serde::Base64;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
#[cfg(feature = "unstable-pre-spec")]
use super::Relation;
use super::{ use super::{
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString, HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, Relation,
ShortAuthenticationString,
}; };
/// The content of a to-device `m.key.verification.start` event. /// The content of a to-device `m.key.verification.start` event.
@ -55,7 +53,6 @@ impl ToDeviceKeyVerificationStartEventContent {
/// ///
/// Begins an SAS key verification process. /// Begins an SAS key verification process.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg(feature = "unstable-pre-spec")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.key.verification.start", kind = Message)] #[ruma_event(type = "m.key.verification.start", kind = Message)]
pub struct KeyVerificationStartEventContent { pub struct KeyVerificationStartEventContent {
@ -71,7 +68,6 @@ pub struct KeyVerificationStartEventContent {
pub relates_to: Relation, pub relates_to: Relation,
} }
#[cfg(feature = "unstable-pre-spec")]
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. /// relation.
@ -93,7 +89,6 @@ pub enum StartMethod {
/// The spec entry for this method can be found [here][1]. /// The spec entry for this method can be found [here][1].
/// ///
/// [1]: https://spec.matrix.org/unstable/client-server-api/#mkeyverificationstartmreciprocatev1 /// [1]: https://spec.matrix.org/unstable/client-server-api/#mkeyverificationstartmreciprocatev1
#[cfg(feature = "unstable-pre-spec")]
ReciprocateV1(ReciprocateV1Content), ReciprocateV1(ReciprocateV1Content),
/// Any unknown start method. /// Any unknown start method.
@ -116,7 +111,6 @@ pub struct _CustomContent {
/// The payload of an `m.key.verification.start` event using the `m.sas.v1` method. /// The payload of an `m.key.verification.start` event using the `m.sas.v1` method.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg(feature = "unstable-pre-spec")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(rename = "m.reciprocate.v1", tag = "method")] #[serde(rename = "m.reciprocate.v1", tag = "method")]
pub struct ReciprocateV1Content { pub struct ReciprocateV1Content {
@ -124,7 +118,6 @@ pub struct ReciprocateV1Content {
pub secret: Base64, pub secret: Base64,
} }
#[cfg(feature = "unstable-pre-spec")]
impl ReciprocateV1Content { impl ReciprocateV1Content {
/// Create a new `ReciprocateV1Content` with the given shared secret. /// Create a new `ReciprocateV1Content` with the given shared secret.
/// ///
@ -208,25 +201,19 @@ mod tests {
use std::collections::BTreeMap; use std::collections::BTreeMap;
use matches::assert_matches; use matches::assert_matches;
#[cfg(feature = "unstable-pre-spec")] use ruma_identifiers::{event_id, user_id};
use ruma_identifiers::event_id;
use ruma_identifiers::user_id;
#[cfg(feature = "unstable-pre-spec")]
use ruma_serde::Base64; use ruma_serde::Base64;
use serde_json::{ use serde_json::{
from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue, from_value as from_json_value, json, to_value as to_json_value, Value as JsonValue,
}; };
use super::{ use super::{
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, SasV1Content, HashAlgorithm, KeyAgreementProtocol, KeyVerificationStartEventContent,
SasV1ContentInit, ShortAuthenticationString, StartMethod, MessageAuthenticationCode, ReciprocateV1Content, SasV1Content, SasV1ContentInit,
ToDeviceKeyVerificationStartEventContent, _CustomContent, ShortAuthenticationString, StartMethod, ToDeviceKeyVerificationStartEventContent,
_CustomContent,
}; };
#[cfg(feature = "unstable-pre-spec")] use crate::{key::verification::Relation, ToDeviceEvent};
use super::{KeyVerificationStartEventContent, ReciprocateV1Content};
#[cfg(feature = "unstable-pre-spec")]
use crate::key::verification::Relation;
use crate::ToDeviceEvent;
#[test] #[test]
fn serialization() { fn serialization() {
@ -294,7 +281,6 @@ mod tests {
assert_eq!(to_json_value(&key_verification_start).unwrap(), json_data); assert_eq!(to_json_value(&key_verification_start).unwrap(), json_data);
#[cfg(feature = "unstable-pre-spec")]
{ {
let secret = Base64::new(b"This is a secret to everybody".to_vec()); let secret = Base64::new(b"This is a secret to everybody".to_vec());
@ -316,7 +302,6 @@ mod tests {
} }
#[test] #[test]
#[cfg(feature = "unstable-pre-spec")]
fn in_room_serialization() { fn in_room_serialization() {
let event_id = event_id!("$1598361704261elfgc:localhost"); let event_id = event_id!("$1598361704261elfgc:localhost");
@ -470,7 +455,6 @@ mod tests {
&& data.get("test").unwrap() == &JsonValue::from("field") && data.get("test").unwrap() == &JsonValue::from("field")
); );
#[cfg(feature = "unstable-pre-spec")]
{ {
let json = json!({ let json = json!({
"content": { "content": {
@ -501,7 +485,6 @@ mod tests {
} }
#[test] #[test]
#[cfg(feature = "unstable-pre-spec")]
fn in_room_deserialization() { fn in_room_deserialization() {
let id = event_id!("$1598361704261elfgc:localhost"); let id = event_id!("$1598361704261elfgc:localhost");

View File

@ -6,9 +6,7 @@ use std::collections::BTreeMap;
use js_int::UInt; use js_int::UInt;
use ruma_events_macros::EventContent; use ruma_events_macros::EventContent;
use ruma_identifiers::DeviceId; use ruma_identifiers::{DeviceId, EventId};
#[cfg(feature = "unstable-pre-spec")]
use ruma_identifiers::EventId;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::room::message::InReplyTo; use crate::room::message::InReplyTo;
@ -99,7 +97,6 @@ pub enum Relation {
Replacement(Replacement), Replacement(Replacement),
/// A reference to another event. /// A reference to another event.
#[cfg(feature = "unstable-pre-spec")]
Reference(Reference), Reference(Reference),
/// An annotation to an event. /// An annotation to an event.
@ -124,14 +121,12 @@ pub struct Replacement {
/// A reference to another event. /// A reference to another event.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg(feature = "unstable-pre-spec")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Reference { pub struct Reference {
/// The event we are referencing. /// The event we are referencing.
pub event_id: Box<EventId>, pub event_id: Box<EventId>,
} }
#[cfg(feature = "unstable-pre-spec")]
impl Reference { impl Reference {
/// Creates a new `Reference` with the given event ID. /// Creates a new `Reference` with the given event ID.
pub fn new(event_id: Box<EventId>) -> Self { pub fn new(event_id: Box<EventId>) -> Self {

View File

@ -1,8 +1,8 @@
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
use super::{Annotation, Reference, Replacement}; use super::{Annotation, Replacement};
use super::{InReplyTo, Relation}; use super::{InReplyTo, Reference, Relation};
impl<'de> Deserialize<'de> for Relation { impl<'de> Deserialize<'de> for Relation {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
@ -14,11 +14,12 @@ impl<'de> Deserialize<'de> for Relation {
return Relation::Reply { in_reply_to }; return Relation::Reply { in_reply_to };
} }
#[cfg(feature = "unstable-pre-spec")]
if let Some(relation) = ev.relates_to.relation { if let Some(relation) = ev.relates_to.relation {
return match relation { return match relation {
#[cfg(feature = "unstable-pre-spec")]
RelationJsonRepr::Annotation(a) => Relation::Annotation(a), RelationJsonRepr::Annotation(a) => Relation::Annotation(a),
RelationJsonRepr::Reference(r) => Relation::Reference(r), RelationJsonRepr::Reference(r) => Relation::Reference(r),
#[cfg(feature = "unstable-pre-spec")]
RelationJsonRepr::Replacement(Replacement { event_id }) => { RelationJsonRepr::Replacement(Replacement { event_id }) => {
Relation::Replacement(Replacement { event_id }) Relation::Replacement(Replacement { event_id })
} }
@ -47,7 +48,6 @@ impl Serialize for Relation {
relation: Some(RelationJsonRepr::Annotation(r.clone())), relation: Some(RelationJsonRepr::Annotation(r.clone())),
..Default::default() ..Default::default()
}, },
#[cfg(feature = "unstable-pre-spec")]
Relation::Reference(r) => RelatesToJsonRepr { Relation::Reference(r) => RelatesToJsonRepr {
relation: Some(RelationJsonRepr::Reference(r.clone())), relation: Some(RelationJsonRepr::Reference(r.clone())),
..Default::default() ..Default::default()
@ -80,31 +80,22 @@ struct RelatesToJsonRepr {
#[serde(rename = "m.in_reply_to", skip_serializing_if = "Option::is_none")] #[serde(rename = "m.in_reply_to", skip_serializing_if = "Option::is_none")]
in_reply_to: Option<InReplyTo>, in_reply_to: Option<InReplyTo>,
#[cfg(feature = "unstable-pre-spec")]
#[serde(flatten, skip_serializing_if = "Option::is_none")] #[serde(flatten, skip_serializing_if = "Option::is_none")]
relation: Option<RelationJsonRepr>, relation: Option<RelationJsonRepr>,
} }
impl RelatesToJsonRepr { impl RelatesToJsonRepr {
fn is_empty(&self) -> bool { fn is_empty(&self) -> bool {
#[cfg(not(feature = "unstable-pre-spec"))] self.in_reply_to.is_none() && self.relation.is_none()
{
self.in_reply_to.is_none()
}
#[cfg(feature = "unstable-pre-spec")]
{
self.in_reply_to.is_none() && self.relation.is_none()
}
} }
} }
/// A relation, which associates new information to an existing event. /// A relation, which associates new information to an existing event.
#[derive(Clone, Deserialize, Serialize)] #[derive(Clone, Deserialize, Serialize)]
#[cfg(feature = "unstable-pre-spec")]
#[serde(tag = "rel_type")] #[serde(tag = "rel_type")]
enum RelationJsonRepr { enum RelationJsonRepr {
/// An annotation to an event. /// An annotation to an event.
#[cfg(feature = "unstable-pre-spec")]
#[serde(rename = "m.annotation")] #[serde(rename = "m.annotation")]
Annotation(Annotation), Annotation(Annotation),
@ -113,6 +104,7 @@ enum RelationJsonRepr {
Reference(Reference), Reference(Reference),
/// An event that replaces another event. /// An event that replaces another event.
#[cfg(feature = "unstable-pre-spec")]
#[serde(rename = "m.replace")] #[serde(rename = "m.replace")]
Replacement(Replacement), Replacement(Replacement),

View File

@ -6,17 +6,13 @@ use std::{borrow::Cow, fmt};
use js_int::UInt; use js_int::UInt;
use ruma_events_macros::EventContent; use ruma_events_macros::EventContent;
#[cfg(feature = "unstable-pre-spec")] use ruma_identifiers::{DeviceId, EventId, MxcUri, UserId};
use ruma_identifiers::{DeviceId, UserId};
use ruma_identifiers::{EventId, MxcUri};
use ruma_serde::{JsonObject, StringEnum}; use ruma_serde::{JsonObject, StringEnum};
use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use super::{EncryptedFile, ImageInfo, ThumbnailInfo}; use super::{EncryptedFile, ImageInfo, ThumbnailInfo};
#[cfg(feature = "unstable-pre-spec")] use crate::{key::verification::VerificationMethod, PrivOwnedStr};
use crate::key::verification::VerificationMethod;
use crate::PrivOwnedStr;
mod content_serde; mod content_serde;
pub mod feedback; pub mod feedback;
@ -215,7 +211,6 @@ pub enum MessageType {
Video(VideoMessageEventContent), Video(VideoMessageEventContent),
/// A request to initiate a key verification. /// A request to initiate a key verification.
#[cfg(feature = "unstable-pre-spec")]
VerificationRequest(KeyVerificationRequestEventContent), VerificationRequest(KeyVerificationRequestEventContent),
/// A custom message. /// A custom message.
@ -253,7 +248,6 @@ impl MessageType {
"m.server_notice" => Self::ServerNotice(deserialize_variant(body, data)?), "m.server_notice" => Self::ServerNotice(deserialize_variant(body, data)?),
"m.text" => Self::Text(deserialize_variant(body, data)?), "m.text" => Self::Text(deserialize_variant(body, data)?),
"m.video" => Self::Video(deserialize_variant(body, data)?), "m.video" => Self::Video(deserialize_variant(body, data)?),
#[cfg(feature = "unstable-pre-spec")]
"m.key.verification.request" => { "m.key.verification.request" => {
Self::VerificationRequest(deserialize_variant(body, data)?) Self::VerificationRequest(deserialize_variant(body, data)?)
} }
@ -273,7 +267,6 @@ impl MessageType {
Self::ServerNotice(_) => "m.server_notice", Self::ServerNotice(_) => "m.server_notice",
Self::Text(_) => "m.text", Self::Text(_) => "m.text",
Self::Video(_) => "m.video", Self::Video(_) => "m.video",
#[cfg(feature = "unstable-pre-spec")]
Self::VerificationRequest(_) => "m.key.verification.request", Self::VerificationRequest(_) => "m.key.verification.request",
Self::_Custom(c) => &c.msgtype, Self::_Custom(c) => &c.msgtype,
} }
@ -291,7 +284,6 @@ impl MessageType {
MessageType::ServerNotice(m) => &m.body, MessageType::ServerNotice(m) => &m.body,
MessageType::Text(m) => &m.body, MessageType::Text(m) => &m.body,
MessageType::Video(m) => &m.body, MessageType::Video(m) => &m.body,
#[cfg(feature = "unstable-pre-spec")]
MessageType::VerificationRequest(m) => &m.body, MessageType::VerificationRequest(m) => &m.body,
MessageType::_Custom(m) => &m.body, MessageType::_Custom(m) => &m.body,
} }
@ -325,7 +317,6 @@ impl MessageType {
Self::ServerNotice(d) => Cow::Owned(serialize(d)), Self::ServerNotice(d) => Cow::Owned(serialize(d)),
Self::Text(d) => Cow::Owned(serialize(d)), Self::Text(d) => Cow::Owned(serialize(d)),
Self::Video(d) => Cow::Owned(serialize(d)), Self::Video(d) => Cow::Owned(serialize(d)),
#[cfg(feature = "unstable-pre-spec")]
Self::VerificationRequest(d) => Cow::Owned(serialize(d)), Self::VerificationRequest(d) => Cow::Owned(serialize(d)),
Self::_Custom(c) => Cow::Borrowed(&c.data), Self::_Custom(c) => Cow::Borrowed(&c.data),
} }
@ -959,7 +950,6 @@ impl VideoInfo {
/// The payload for a key verification request message. /// The payload for a key verification request message.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg(feature = "unstable-pre-spec")]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[serde(tag = "msgtype", rename = "m.key.verification.request")] #[serde(tag = "msgtype", rename = "m.key.verification.request")]
pub struct KeyVerificationRequestEventContent { pub struct KeyVerificationRequestEventContent {
@ -981,7 +971,6 @@ pub struct KeyVerificationRequestEventContent {
pub to: Box<UserId>, pub to: Box<UserId>,
} }
#[cfg(feature = "unstable-pre-spec")]
impl KeyVerificationRequestEventContent { impl KeyVerificationRequestEventContent {
/// Creates a new `RoomKeyVerificationRequestEventContent` with the given body, method, device /// Creates a new `RoomKeyVerificationRequestEventContent` with the given body, method, device
/// and user ID. /// and user ID.

View File

@ -82,7 +82,6 @@ pub fn get_plain_quote_fallback(original_message: &impl ReplyBaseEvent) -> Strin
MessageType::_Custom(content) => { MessageType::_Custom(content) => {
format!("> <{}> {}", sender, content.body) format!("> <{}> {}", sender, content.body)
} }
#[cfg(feature = "unstable-pre-spec")]
MessageType::VerificationRequest(content) => { MessageType::VerificationRequest(content) => {
format!("> <{}> {}", sender, content.body) format!("> <{}> {}", sender, content.body)
} }
@ -268,7 +267,6 @@ pub fn get_html_quote_fallback(original_message: &RoomMessageEvent) -> String {
body = content.body, body = content.body,
) )
} }
#[cfg(feature = "unstable-pre-spec")]
MessageType::VerificationRequest(content) => { MessageType::VerificationRequest(content) => {
formatdoc!( formatdoc!(
" "

View File

@ -335,13 +335,11 @@ fn serialize_and_deserialize_from_display_form() {
serde_json_eq(RoomAccountDataEventType::FullyRead, json!("m.fully_read")); serde_json_eq(RoomAccountDataEventType::FullyRead, json!("m.fully_read"));
serde_json_eq(EventType::KeyVerificationAccept, json!("m.key.verification.accept")); serde_json_eq(EventType::KeyVerificationAccept, json!("m.key.verification.accept"));
serde_json_eq(EventType::KeyVerificationCancel, json!("m.key.verification.cancel")); serde_json_eq(EventType::KeyVerificationCancel, json!("m.key.verification.cancel"));
// m.key.verification.ready is unstable-pre-spec serde_json_eq(EventType::KeyVerificationDone, json!("m.key.verification.done"));
// serde_json_eq(EventType::KeyVerificationDone, json!("m.key.verification.done"));
serde_json_eq(EventType::KeyVerificationKey, json!("m.key.verification.key")); serde_json_eq(EventType::KeyVerificationKey, json!("m.key.verification.key"));
serde_json_eq(ToDeviceEventType::KeyVerificationKey, json!("m.key.verification.key")); serde_json_eq(ToDeviceEventType::KeyVerificationKey, json!("m.key.verification.key"));
serde_json_eq(EventType::KeyVerificationMac, json!("m.key.verification.mac")); serde_json_eq(EventType::KeyVerificationMac, json!("m.key.verification.mac"));
// m.key.verification.ready is unstable-pre-spec serde_json_eq(EventType::KeyVerificationReady, json!("m.key.verification.ready"));
// serde_json_eq(EventType::KeyVerificationReady, json!("m.key.verification.ready"));
serde_json_eq(EventType::KeyVerificationRequest, json!("m.key.verification.request")); serde_json_eq(EventType::KeyVerificationRequest, json!("m.key.verification.request"));
serde_json_eq(EventType::KeyVerificationStart, json!("m.key.verification.start")); serde_json_eq(EventType::KeyVerificationStart, json!("m.key.verification.start"));
serde_json_eq(EventType::IgnoredUserList, json!("m.ignored_user_list")); serde_json_eq(EventType::IgnoredUserList, json!("m.ignored_user_list"));

View File

@ -4,20 +4,15 @@ use assign::assign;
use js_int::uint; use js_int::uint;
use matches::assert_matches; use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_common::MilliSecondsSinceUnixEpoch;
#[cfg(feature = "unstable-pre-spec")]
use ruma_events::{
key::verification::VerificationMethod, room::message::KeyVerificationRequestEventContent,
};
use ruma_events::{ use ruma_events::{
key::verification::VerificationMethod,
room::message::{ room::message::{
AudioMessageEventContent, InReplyTo, MessageType, Relation, RoomMessageEvent, AudioMessageEventContent, InReplyTo, KeyVerificationRequestEventContent, MessageType,
RoomMessageEventContent, TextMessageEventContent, Relation, RoomMessageEvent, RoomMessageEventContent, TextMessageEventContent,
}, },
Unsigned, Unsigned,
}; };
#[cfg(feature = "unstable-pre-spec")] use ruma_identifiers::{event_id, mxc_uri, room_id, user_id, DeviceId};
use ruma_identifiers::DeviceId;
use ruma_identifiers::{event_id, mxc_uri, room_id, user_id};
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};
macro_rules! json_object { macro_rules! json_object {
@ -297,7 +292,6 @@ fn edit_deserialization_future() {
} }
#[test] #[test]
#[cfg(feature = "unstable-pre-spec")]
fn verification_request_deserialization() { fn verification_request_deserialization() {
let user_id = user_id!("@example2:localhost"); let user_id = user_id!("@example2:localhost");
let device_id: Box<DeviceId> = "XOWLHHFSWM".into(); let device_id: Box<DeviceId> = "XOWLHHFSWM".into();
@ -333,7 +327,6 @@ fn verification_request_deserialization() {
} }
#[test] #[test]
#[cfg(feature = "unstable-pre-spec")]
fn verification_request_serialization() { fn verification_request_serialization() {
let user_id = user_id!("@example2:localhost").to_owned(); let user_id = user_id!("@example2:localhost").to_owned();
let device_id: Box<DeviceId> = "XOWLHHFSWM".into(); let device_id: Box<DeviceId> = "XOWLHHFSWM".into();