Rename *ToDeviceEventContent structs to ToDevice*Content

This commit is contained in:
Jonas Platte 2021-10-01 16:36:50 +02:00
parent 6b575ca0a2
commit 0101e110f8
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
18 changed files with 100 additions and 99 deletions

View File

@ -866,7 +866,7 @@ fn to_event_path(name: &LitStr, struct_name: &Ident, ruma_events: &TokenStream)
quote! { #ruma_events::#struct_name<#ruma_events::#( #path )::*::#content> } quote! { #ruma_events::#struct_name<#ruma_events::#( #path )::*::#content> }
} }
"ToDeviceEvent" => { "ToDeviceEvent" => {
let content = format_ident!("{}ToDeviceEventContent", event); let content = format_ident!("ToDevice{}EventContent", event);
quote! { #ruma_events::#struct_name<#ruma_events::#( #path )::*::#content> } quote! { #ruma_events::#struct_name<#ruma_events::#( #path )::*::#content> }
} }
struct_str if struct_str.contains("Redacted") => { struct_str if struct_str.contains("Redacted") => {
@ -902,7 +902,7 @@ fn to_event_content_path(
let content_str = match kind { let content_str = match kind {
EventKind::ToDevice => { EventKind::ToDevice => {
format_ident!("{}{}ToDeviceEventContent", prefix.unwrap_or(""), event) format_ident!("ToDevice{}{}EventContent", prefix.unwrap_or(""), event)
} }
_ => format_ident!("{}{}EventContent", prefix.unwrap_or(""), event), _ => format_ident!("{}{}EventContent", prefix.unwrap_or(""), event),
}; };

View File

@ -7,6 +7,7 @@ Breaking changes:
* Use `Box<RawJsonValue>` instead of `JsonValue` for PDU `content` field * Use `Box<RawJsonValue>` instead of `JsonValue` for PDU `content` field
* Require `room::message::MessageType` to always contain a body * Require `room::message::MessageType` to always contain a body
* The `new` constructor now also has a body parameter * The `new` constructor now also has a body parameter
* Rename `*ToDeviceEventContent` structs to `ToDevice*Content`
Improvements: Improvements:

View File

@ -22,16 +22,16 @@ use serde::{
#[derive(Clone, Debug, Default, EventContent)] #[derive(Clone, Debug, Default, EventContent)]
#[allow(clippy::exhaustive_structs)] #[allow(clippy::exhaustive_structs)]
#[ruma_event(type = "m.dummy", kind = ToDevice)] #[ruma_event(type = "m.dummy", kind = ToDevice)]
pub struct DummyToDeviceEventContent; pub struct ToDeviceDummyEventContent;
impl DummyToDeviceEventContent { impl ToDeviceDummyEventContent {
/// Create a new `DummyToDeviceEventContent`. /// Create a new `ToDeviceDummyEventContent`.
pub fn new() -> Self { pub fn new() -> Self {
Self Self
} }
} }
impl<'de> Deserialize<'de> for DummyToDeviceEventContent { impl<'de> Deserialize<'de> for ToDeviceDummyEventContent {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
@ -39,7 +39,7 @@ impl<'de> Deserialize<'de> for DummyToDeviceEventContent {
struct Visitor; struct Visitor;
impl<'de> de::Visitor<'de> for Visitor { impl<'de> de::Visitor<'de> for Visitor {
type Value = DummyToDeviceEventContent; type Value = ToDeviceDummyEventContent;
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a struct") formatter.write_str("a struct")
@ -50,19 +50,19 @@ impl<'de> Deserialize<'de> for DummyToDeviceEventContent {
A: de::MapAccess<'de>, A: de::MapAccess<'de>,
{ {
while map.next_entry::<de::IgnoredAny, de::IgnoredAny>()?.is_some() {} while map.next_entry::<de::IgnoredAny, de::IgnoredAny>()?.is_some() {}
Ok(DummyToDeviceEventContent) Ok(ToDeviceDummyEventContent)
} }
} }
deserializer.deserialize_struct("DummyToDeviceEventContent", &[], Visitor) deserializer.deserialize_struct("ToDeviceDummyEventContent", &[], Visitor)
} }
} }
impl Serialize for DummyToDeviceEventContent { impl Serialize for ToDeviceDummyEventContent {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where
S: Serializer, S: Serializer,
{ {
serializer.serialize_struct("DummyToDeviceEventContent", 0)?.end() serializer.serialize_struct("ToDeviceDummyEventContent", 0)?.end()
} }
} }

View File

@ -6,12 +6,12 @@ use serde::{Deserialize, Serialize};
/// The content of an `m.forwarded_room_key` event. /// The content of an `m.forwarded_room_key` event.
/// ///
/// To create an instance of this type, first create a `ForwardedRoomKeyToDeviceEventContentInit` /// To create an instance of this type, first create a `ToDeviceForwardedRoomKeyEventContentInit`
/// and convert it via `ForwardedRoomKeyToDeviceEventContent::from` / `.into()`. /// and convert it via `ToDeviceForwardedRoomKeyEventContent::from` / `.into()`.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.forwarded_room_key", kind = ToDevice)] #[ruma_event(type = "m.forwarded_room_key", kind = ToDevice)]
pub struct ForwardedRoomKeyToDeviceEventContent { pub struct ToDeviceForwardedRoomKeyEventContent {
/// The encryption algorithm the key in this event is to be used with. /// The encryption algorithm the key in this event is to be used with.
pub algorithm: EventEncryptionAlgorithm, pub algorithm: EventEncryptionAlgorithm,
@ -43,13 +43,13 @@ pub struct ForwardedRoomKeyToDeviceEventContent {
pub forwarding_curve25519_key_chain: Vec<String>, pub forwarding_curve25519_key_chain: Vec<String>,
} }
/// Initial set of fields of `ForwardedRoomKeyToDeviceEventContent`. /// Initial set of fields of `ToDeviceForwardedRoomKeyEventContent`.
/// ///
/// This struct will not be updated even if additional fields are added to `ConditionalPushRule` in /// This struct will not be updated even if additional fields are added to `ConditionalPushRule` in
/// a new (non-breaking) release of the Matrix specification. /// a new (non-breaking) release of the Matrix specification.
#[derive(Debug)] #[derive(Debug)]
#[allow(clippy::exhaustive_structs)] #[allow(clippy::exhaustive_structs)]
pub struct ForwardedRoomKeyToDeviceEventContentInit { pub struct ToDeviceForwardedRoomKeyEventContentInit {
/// The encryption algorithm the key in this event is to be used with. /// The encryption algorithm the key in this event is to be used with.
pub algorithm: EventEncryptionAlgorithm, pub algorithm: EventEncryptionAlgorithm,
@ -81,8 +81,8 @@ pub struct ForwardedRoomKeyToDeviceEventContentInit {
pub forwarding_curve25519_key_chain: Vec<String>, pub forwarding_curve25519_key_chain: Vec<String>,
} }
impl From<ForwardedRoomKeyToDeviceEventContentInit> for ForwardedRoomKeyToDeviceEventContent { impl From<ToDeviceForwardedRoomKeyEventContentInit> for ToDeviceForwardedRoomKeyEventContent {
fn from(init: ForwardedRoomKeyToDeviceEventContentInit) -> Self { fn from(init: ToDeviceForwardedRoomKeyEventContentInit) -> Self {
Self { Self {
algorithm: init.algorithm, algorithm: init.algorithm,
room_id: init.room_id, room_id: init.room_id,

View File

@ -18,7 +18,7 @@ use super::{
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.key.verification.accept", kind = ToDevice)] #[ruma_event(type = "m.key.verification.accept", kind = ToDevice)]
pub struct AcceptToDeviceEventContent { pub struct ToDeviceAcceptEventContent {
/// An opaque identifier for the verification process. /// An opaque identifier for the verification process.
/// ///
/// Must be the same as the one used for the *m.key.verification.start* message. /// Must be the same as the one used for the *m.key.verification.start* message.
@ -29,8 +29,8 @@ pub struct AcceptToDeviceEventContent {
pub method: AcceptMethod, pub method: AcceptMethod,
} }
impl AcceptToDeviceEventContent { impl ToDeviceAcceptEventContent {
/// Creates a new `AcceptToDeviceEventContent` with the given transaction ID and method-specific /// Creates a new `ToDeviceAcceptEventContent` with the given transaction ID and method-specific
/// content. /// content.
pub fn new(transaction_id: String, method: AcceptMethod) -> Self { pub fn new(transaction_id: String, method: AcceptMethod) -> Self {
Self { transaction_id, method } Self { transaction_id, method }
@ -57,7 +57,7 @@ pub struct AcceptEventContent {
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
impl AcceptEventContent { impl AcceptEventContent {
/// Creates a new `AcceptToDeviceEventContent` with the given method-specific content and /// Creates a new `ToDeviceAcceptEventContent` with the given method-specific content and
/// relation. /// relation.
pub fn new(method: AcceptMethod, relates_to: Relation) -> Self { pub fn new(method: AcceptMethod, relates_to: Relation) -> Self {
Self { method, relates_to } Self { method, relates_to }
@ -176,8 +176,8 @@ mod tests {
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
use super::AcceptEventContent; use super::AcceptEventContent;
use super::{ use super::{
AcceptMethod, AcceptToDeviceEventContent, HashAlgorithm, KeyAgreementProtocol, AcceptMethod, HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, SasV1Content,
MessageAuthenticationCode, SasV1Content, ShortAuthenticationString, _CustomContent, ShortAuthenticationString, ToDeviceAcceptEventContent, _CustomContent,
}; };
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
use crate::key::verification::Relation; use crate::key::verification::Relation;
@ -185,7 +185,7 @@ mod tests {
#[test] #[test]
fn serialization() { fn serialization() {
let key_verification_accept_content = AcceptToDeviceEventContent { let key_verification_accept_content = ToDeviceAcceptEventContent {
transaction_id: "456".into(), transaction_id: "456".into(),
method: AcceptMethod::SasV1(SasV1Content { method: AcceptMethod::SasV1(SasV1Content {
hash: HashAlgorithm::Sha256, hash: HashAlgorithm::Sha256,
@ -229,7 +229,7 @@ mod tests {
"type": "m.key.verification.accept" "type": "m.key.verification.accept"
}); });
let key_verification_accept_content = AcceptToDeviceEventContent { let key_verification_accept_content = ToDeviceAcceptEventContent {
transaction_id: "456".into(), transaction_id: "456".into(),
method: AcceptMethod::_Custom(_CustomContent { method: AcceptMethod::_Custom(_CustomContent {
method: "m.sas.custom".to_owned(), method: "m.sas.custom".to_owned(),
@ -291,8 +291,8 @@ mod tests {
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it. // Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
assert_matches!( assert_matches!(
from_json_value::<AcceptToDeviceEventContent>(json).unwrap(), from_json_value::<ToDeviceAcceptEventContent>(json).unwrap(),
AcceptToDeviceEventContent { ToDeviceAcceptEventContent {
transaction_id, transaction_id,
method: AcceptMethod::SasV1(SasV1Content { method: AcceptMethod::SasV1(SasV1Content {
commitment, commitment,
@ -326,10 +326,10 @@ mod tests {
}); });
assert_matches!( assert_matches!(
from_json_value::<ToDeviceEvent<AcceptToDeviceEventContent>>(json).unwrap(), from_json_value::<ToDeviceEvent<ToDeviceAcceptEventContent>>(json).unwrap(),
ToDeviceEvent { ToDeviceEvent {
sender, sender,
content: AcceptToDeviceEventContent { content: ToDeviceAcceptEventContent {
transaction_id, transaction_id,
method: AcceptMethod::SasV1(SasV1Content { method: AcceptMethod::SasV1(SasV1Content {
commitment, commitment,
@ -362,10 +362,10 @@ mod tests {
}); });
assert_matches!( assert_matches!(
from_json_value::<ToDeviceEvent<AcceptToDeviceEventContent>>(json).unwrap(), from_json_value::<ToDeviceEvent<ToDeviceAcceptEventContent>>(json).unwrap(),
ToDeviceEvent { ToDeviceEvent {
sender, sender,
content: AcceptToDeviceEventContent { content: ToDeviceAcceptEventContent {
transaction_id, transaction_id,
method: AcceptMethod::_Custom(_CustomContent { method: AcceptMethod::_Custom(_CustomContent {
method, method,

View File

@ -13,7 +13,7 @@ use super::Relation;
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[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 = ToDevice)] #[ruma_event(type = "m.key.verification.cancel", kind = ToDevice)]
pub struct CancelToDeviceEventContent { pub struct ToDeviceCancelEventContent {
/// The opaque identifier for the verification process/request. /// The opaque identifier for the verification process/request.
pub transaction_id: String, pub transaction_id: String,
@ -26,8 +26,8 @@ pub struct CancelToDeviceEventContent {
pub code: CancelCode, pub code: CancelCode,
} }
impl CancelToDeviceEventContent { impl ToDeviceCancelEventContent {
/// Creates a new `CancelToDeviceEventContent` with the given transaction ID, reason and code. /// Creates a new `ToDeviceCancelEventContent` with the given transaction ID, reason and code.
pub fn new(transaction_id: String, reason: String, code: CancelCode) -> Self { pub fn new(transaction_id: String, reason: String, code: CancelCode) -> Self {
Self { transaction_id, reason, code } Self { transaction_id, reason, code }
} }

View File

@ -11,15 +11,15 @@ use super::Relation;
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.key.verification.done", kind = ToDevice)] #[ruma_event(type = "m.key.verification.done", kind = ToDevice)]
pub struct DoneToDeviceEventContent { pub struct ToDeviceDoneEventContent {
/// An opaque identifier for the verification process. /// An opaque identifier for the verification process.
/// ///
/// Must be the same as the one used for the *m.key.verification.start* message. /// Must be the same as the one used for the *m.key.verification.start* message.
pub transaction_id: String, pub transaction_id: String,
} }
impl DoneToDeviceEventContent { impl ToDeviceDoneEventContent {
/// Creates a new `DoneToDeviceEventContent` with the given transaction ID. /// Creates a new `ToDeviceDoneEventContent` with the given transaction ID.
pub fn new(transaction_id: String) -> Self { pub fn new(transaction_id: String) -> Self {
Self { transaction_id } Self { transaction_id }
} }

View File

@ -12,7 +12,7 @@ use super::Relation;
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[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 = ToDevice)] #[ruma_event(type = "m.key.verification.key", kind = ToDevice)]
pub struct KeyToDeviceEventContent { pub struct ToDeviceKeyEventContent {
/// An opaque identifier for the verification process. /// An opaque identifier for the verification process.
/// ///
/// Must be the same as the one used for the *m.key.verification.start* message. /// Must be the same as the one used for the *m.key.verification.start* message.
@ -22,8 +22,8 @@ pub struct KeyToDeviceEventContent {
pub key: String, pub key: String,
} }
impl KeyToDeviceEventContent { impl ToDeviceKeyEventContent {
/// Creates a new `KeyToDeviceEventContent` with the given transaction ID and key. /// Creates a new `ToDeviceKeyEventContent` with the given transaction ID and key.
pub fn new(transaction_id: String, key: String) -> Self { pub fn new(transaction_id: String, key: String) -> Self {
Self { transaction_id, key } Self { transaction_id, key }
} }

View File

@ -14,7 +14,7 @@ use super::Relation;
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[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 = ToDevice)] #[ruma_event(type = "m.key.verification.mac", kind = ToDevice)]
pub struct MacToDeviceEventContent { pub struct ToDeviceMacEventContent {
/// An opaque identifier for the verification process. /// An opaque identifier for the verification process.
/// ///
/// Must be the same as the one used for the *m.key.verification.start* message. /// Must be the same as the one used for the *m.key.verification.start* message.
@ -30,9 +30,9 @@ pub struct MacToDeviceEventContent {
pub keys: String, pub keys: String,
} }
impl MacToDeviceEventContent { impl ToDeviceMacEventContent {
/// Creates a new `MacToDeviceEventContent` with the given transaction ID, key ID to MAC map and /// Creates a new `ToDeviceMacEventContent` with the given transaction ID, key ID to MAC
/// key MAC. /// map and key MAC.
pub fn new(transaction_id: String, mac: BTreeMap<String, String>, keys: String) -> Self { pub fn new(transaction_id: String, mac: BTreeMap<String, String>, keys: String) -> Self {
Self { transaction_id, mac, keys } Self { transaction_id, mac, keys }
} }

View File

@ -12,7 +12,7 @@ use super::{Relation, VerificationMethod};
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.key.verification.ready", kind = ToDevice)] #[ruma_event(type = "m.key.verification.ready", kind = ToDevice)]
pub struct ReadyToDeviceEventContent { pub struct ToDeviceReadyEventContent {
/// The device ID which is initiating the request. /// The device ID which is initiating the request.
pub from_device: DeviceIdBox, pub from_device: DeviceIdBox,
@ -27,8 +27,8 @@ pub struct ReadyToDeviceEventContent {
pub transaction_id: String, pub transaction_id: String,
} }
impl ReadyToDeviceEventContent { impl ToDeviceReadyEventContent {
/// Creates a new `ReadyToDeviceEventContent` with the given device ID, verification methods and /// Creates a new `ToDeviceReadyEventContent` with the given device ID, verification methods and
/// transaction ID. /// transaction ID.
pub fn new( pub fn new(
from_device: DeviceIdBox, from_device: DeviceIdBox,
@ -75,7 +75,7 @@ mod tests {
use ruma_identifiers::{event_id, DeviceIdBox}; use ruma_identifiers::{event_id, DeviceIdBox};
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::{ReadyEventContent, ReadyToDeviceEventContent}; use super::{ReadyEventContent, ToDeviceReadyEventContent};
use crate::key::verification::{Relation, VerificationMethod}; use crate::key::verification::{Relation, VerificationMethod};
#[test] #[test]
@ -106,7 +106,7 @@ mod tests {
"transaction_id": "456", "transaction_id": "456",
}); });
let content = ReadyToDeviceEventContent { let content = ToDeviceReadyEventContent {
from_device: device, from_device: device,
transaction_id: "456".to_owned(), transaction_id: "456".to_owned(),
methods: vec![VerificationMethod::SasV1], methods: vec![VerificationMethod::SasV1],
@ -149,8 +149,8 @@ mod tests {
}); });
assert_matches!( assert_matches!(
from_json_value::<ReadyToDeviceEventContent>(json_data).unwrap(), from_json_value::<ToDeviceReadyEventContent>(json_data).unwrap(),
ReadyToDeviceEventContent { ToDeviceReadyEventContent {
from_device, from_device,
transaction_id, transaction_id,
methods, methods,

View File

@ -11,7 +11,7 @@ use super::VerificationMethod;
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.key.verification.request", kind = ToDevice)] #[ruma_event(type = "m.key.verification.request", kind = ToDevice)]
pub struct RequestToDeviceEventContent { pub struct ToDeviceRequestEventContent {
/// The device ID which is initiating the request. /// The device ID which is initiating the request.
pub from_device: DeviceIdBox, pub from_device: DeviceIdBox,
@ -30,8 +30,8 @@ pub struct RequestToDeviceEventContent {
pub timestamp: MilliSecondsSinceUnixEpoch, pub timestamp: MilliSecondsSinceUnixEpoch,
} }
impl RequestToDeviceEventContent { impl ToDeviceRequestEventContent {
/// Creates a new `RequestToDeviceEventContent` with the given device ID, transaction ID, /// Creates a new `ToDeviceRequestEventContent` with the given device ID, transaction ID,
/// methods and timestamp. /// methods and timestamp.
pub fn new( pub fn new(
from_device: DeviceIdBox, from_device: DeviceIdBox,

View File

@ -19,7 +19,7 @@ use super::{
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[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 = ToDevice)] #[ruma_event(type = "m.key.verification.start", kind = ToDevice)]
pub struct StartToDeviceEventContent { pub struct ToDeviceStartEventContent {
/// The device ID which is initiating the process. /// The device ID which is initiating the process.
pub from_device: DeviceIdBox, pub from_device: DeviceIdBox,
@ -35,8 +35,8 @@ pub struct StartToDeviceEventContent {
pub method: StartMethod, pub method: StartMethod,
} }
impl StartToDeviceEventContent { impl ToDeviceStartEventContent {
/// Creates a new `StartToDeviceEventContent` with the given device ID, transaction ID and /// Creates a new `ToDeviceStartEventContent` with the given device ID, transaction ID and
/// method specific content. /// method specific content.
pub fn new(from_device: DeviceIdBox, transaction_id: String, method: StartMethod) -> Self { pub fn new(from_device: DeviceIdBox, transaction_id: String, method: StartMethod) -> Self {
Self { from_device, transaction_id, method } Self { from_device, transaction_id, method }
@ -210,7 +210,7 @@ mod tests {
use super::{ use super::{
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, SasV1Content, HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, SasV1Content,
SasV1ContentInit, ShortAuthenticationString, StartMethod, StartToDeviceEventContent, SasV1ContentInit, ShortAuthenticationString, StartMethod, ToDeviceStartEventContent,
_CustomContent, _CustomContent,
}; };
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
@ -221,7 +221,7 @@ mod tests {
#[test] #[test]
fn serialization() { fn serialization() {
let key_verification_start_content = StartToDeviceEventContent { let key_verification_start_content = ToDeviceStartEventContent {
from_device: "123".into(), from_device: "123".into(),
transaction_id: "456".into(), transaction_id: "456".into(),
method: StartMethod::SasV1( method: StartMethod::SasV1(
@ -269,7 +269,7 @@ mod tests {
"sender": sender "sender": sender
}); });
let key_verification_start_content = StartToDeviceEventContent { let key_verification_start_content = ToDeviceStartEventContent {
from_device: "123".into(), from_device: "123".into(),
transaction_id: "456".into(), transaction_id: "456".into(),
method: StartMethod::_Custom(_CustomContent { method: StartMethod::_Custom(_CustomContent {
@ -289,7 +289,7 @@ mod tests {
{ {
let secret = "This is a secret to everybody".to_owned(); let secret = "This is a secret to everybody".to_owned();
let key_verification_start_content = StartToDeviceEventContent { let key_verification_start_content = ToDeviceStartEventContent {
from_device: "123".into(), from_device: "123".into(),
transaction_id: "456".into(), transaction_id: "456".into(),
method: StartMethod::ReciprocateV1(ReciprocateV1Content::new(secret.clone())), method: StartMethod::ReciprocateV1(ReciprocateV1Content::new(secret.clone())),
@ -375,8 +375,8 @@ mod tests {
// Deserialize the content struct separately to verify `TryFromRaw` is implemented for it. // Deserialize the content struct separately to verify `TryFromRaw` is implemented for it.
assert_matches!( assert_matches!(
from_json_value::<StartToDeviceEventContent>(json).unwrap(), from_json_value::<ToDeviceStartEventContent>(json).unwrap(),
StartToDeviceEventContent { ToDeviceStartEventContent {
from_device, from_device,
transaction_id, transaction_id,
method: StartMethod::SasV1(SasV1Content { method: StartMethod::SasV1(SasV1Content {
@ -410,10 +410,10 @@ mod tests {
}); });
assert_matches!( assert_matches!(
from_json_value::<ToDeviceEvent<StartToDeviceEventContent>>(json).unwrap(), from_json_value::<ToDeviceEvent<ToDeviceStartEventContent>>(json).unwrap(),
ToDeviceEvent { ToDeviceEvent {
sender, sender,
content: StartToDeviceEventContent { content: ToDeviceStartEventContent {
from_device, from_device,
transaction_id, transaction_id,
method: StartMethod::SasV1(SasV1Content { method: StartMethod::SasV1(SasV1Content {
@ -446,10 +446,10 @@ mod tests {
}); });
assert_matches!( assert_matches!(
from_json_value::<ToDeviceEvent<StartToDeviceEventContent>>(json).unwrap(), from_json_value::<ToDeviceEvent<ToDeviceStartEventContent>>(json).unwrap(),
ToDeviceEvent { ToDeviceEvent {
sender, sender,
content: StartToDeviceEventContent { content: ToDeviceStartEventContent {
from_device, from_device,
transaction_id, transaction_id,
method: StartMethod::_Custom(_CustomContent { method, data }) method: StartMethod::_Custom(_CustomContent { method, data })
@ -475,10 +475,10 @@ mod tests {
}); });
assert_matches!( assert_matches!(
from_json_value::<ToDeviceEvent<StartToDeviceEventContent>>(json).unwrap(), from_json_value::<ToDeviceEvent<ToDeviceStartEventContent>>(json).unwrap(),
ToDeviceEvent { ToDeviceEvent {
sender, sender,
content: StartToDeviceEventContent { content: ToDeviceStartEventContent {
from_device, from_device,
transaction_id, transaction_id,
method: StartMethod::ReciprocateV1(ReciprocateV1Content { secret }), method: StartMethod::ReciprocateV1(ReciprocateV1Content { secret }),

View File

@ -48,20 +48,20 @@ impl From<EncryptedEventScheme> for EncryptedEventContent {
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.room.encrypted", kind = ToDevice)] #[ruma_event(type = "m.room.encrypted", kind = ToDevice)]
pub struct EncryptedToDeviceEventContent { pub struct ToDeviceEncryptedEventContent {
/// Algorithm-specific fields. /// Algorithm-specific fields.
#[serde(flatten)] #[serde(flatten)]
pub scheme: EncryptedEventScheme, pub scheme: EncryptedEventScheme,
} }
impl EncryptedToDeviceEventContent { impl ToDeviceEncryptedEventContent {
/// Creates a new `EncryptedToDeviceEventContent` with the given scheme. /// Creates a new `ToDeviceEncryptedEventContent` with the given scheme.
pub fn new(scheme: EncryptedEventScheme) -> Self { pub fn new(scheme: EncryptedEventScheme) -> Self {
Self { scheme } Self { scheme }
} }
} }
impl From<EncryptedEventScheme> for EncryptedToDeviceEventContent { impl From<EncryptedEventScheme> for ToDeviceEncryptedEventContent {
fn from(scheme: EncryptedEventScheme) -> Self { fn from(scheme: EncryptedEventScheme) -> Self {
Self { scheme } Self { scheme }
} }

View File

@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.room_key", kind = ToDevice)] #[ruma_event(type = "m.room_key", kind = ToDevice)]
pub struct RoomKeyToDeviceEventContent { pub struct ToDeviceRoomKeyEventContent {
/// The encryption algorithm the key in this event is to be used with. /// The encryption algorithm the key in this event is to be used with.
/// ///
/// Must be `m.megolm.v1.aes-sha2`. /// Must be `m.megolm.v1.aes-sha2`.
@ -26,8 +26,8 @@ pub struct RoomKeyToDeviceEventContent {
pub session_key: String, pub session_key: String,
} }
impl RoomKeyToDeviceEventContent { impl ToDeviceRoomKeyEventContent {
/// Creates a new `RoomKeyToDeviceEventContent` with the given algorithm, room ID, session ID /// Creates a new `ToDeviceRoomKeyEventContent` with the given algorithm, room ID, session ID
/// and session key. /// and session key.
pub fn new( pub fn new(
algorithm: EventEncryptionAlgorithm, algorithm: EventEncryptionAlgorithm,
@ -44,13 +44,13 @@ mod tests {
use ruma_identifiers::{room_id, user_id, EventEncryptionAlgorithm}; use ruma_identifiers::{room_id, user_id, EventEncryptionAlgorithm};
use serde_json::{json, to_value as to_json_value}; use serde_json::{json, to_value as to_json_value};
use super::RoomKeyToDeviceEventContent; use super::ToDeviceRoomKeyEventContent;
use crate::ToDeviceEvent; use crate::ToDeviceEvent;
#[test] #[test]
fn serialization() { fn serialization() {
let ev = ToDeviceEvent { let ev = ToDeviceEvent {
content: RoomKeyToDeviceEventContent { content: ToDeviceRoomKeyEventContent {
algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2, algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2,
room_id: room_id!("!testroomid:example.org"), room_id: room_id!("!testroomid:example.org"),
session_id: "SessId".into(), session_id: "SessId".into(),

View File

@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.room_key_request", kind = ToDevice)] #[ruma_event(type = "m.room_key_request", kind = ToDevice)]
pub struct RoomKeyRequestToDeviceEventContent { pub struct ToDeviceRoomKeyRequestEventContent {
/// Whether this is a new key request or a cancellation of a previous request. /// Whether this is a new key request or a cancellation of a previous request.
pub action: Action, pub action: Action,
@ -28,8 +28,8 @@ pub struct RoomKeyRequestToDeviceEventContent {
pub request_id: String, pub request_id: String,
} }
impl RoomKeyRequestToDeviceEventContent { impl ToDeviceRoomKeyRequestEventContent {
/// Creates a new `RoomKeyRequestToDeviceEventContent` with the given action, boyd, device ID /// Creates a new `ToDeviceRoomKeyRequestEventContent` with the given action, boyd, device ID
/// and request ID. /// and request ID.
pub fn new( pub fn new(
action: Action, action: Action,

View File

@ -15,7 +15,7 @@ use serde::{ser::SerializeStruct, Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize, EventContent)] #[derive(Clone, Debug, Serialize, Deserialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.secret.request", kind = ToDevice)] #[ruma_event(type = "m.secret.request", kind = ToDevice)]
pub struct RequestToDeviceEventContent { pub struct ToDeviceRequestEventContent {
/// The action for the request. /// The action for the request.
#[serde(flatten)] #[serde(flatten)]
pub action: RequestAction, pub action: RequestAction,
@ -31,8 +31,8 @@ pub struct RequestToDeviceEventContent {
pub request_id: String, pub request_id: String,
} }
impl RequestToDeviceEventContent { impl ToDeviceRequestEventContent {
/// Creates a new `RequestToDeviceEventContent` with the given action, requesting device ID and /// Creates a new `ToDeviceRequestEventContent` with the given action, requesting device ID and
/// request ID. /// request ID.
pub fn new( pub fn new(
action: RequestAction, action: RequestAction,
@ -133,13 +133,13 @@ pub enum SecretName {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::{RequestAction, RequestToDeviceEventContent, SecretName}; use super::{RequestAction, SecretName, ToDeviceRequestEventContent};
use matches::assert_matches; use matches::assert_matches;
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};
#[test] #[test]
fn secret_request_serialization() { fn secret_request_serialization() {
let content = RequestToDeviceEventContent::new( let content = ToDeviceRequestEventContent::new(
RequestAction::Request("org.example.some.secret".into()), RequestAction::Request("org.example.some.secret".into()),
"ABCDEFG".into(), "ABCDEFG".into(),
"randomly_generated_id_9573".into(), "randomly_generated_id_9573".into(),
@ -157,7 +157,7 @@ mod test {
#[test] #[test]
fn secret_request_recovery_key_serialization() { fn secret_request_recovery_key_serialization() {
let content = RequestToDeviceEventContent::new( let content = ToDeviceRequestEventContent::new(
RequestAction::Request(SecretName::RecoveryKey), RequestAction::Request(SecretName::RecoveryKey),
"XYZxyz".into(), "XYZxyz".into(),
"this_is_a_request_id".into(), "this_is_a_request_id".into(),
@ -175,7 +175,7 @@ mod test {
#[test] #[test]
fn secret_custom_action_serialization() { fn secret_custom_action_serialization() {
let content = RequestToDeviceEventContent::new( let content = ToDeviceRequestEventContent::new(
RequestAction::_Custom("my_custom_action".into()), RequestAction::_Custom("my_custom_action".into()),
"XYZxyz".into(), "XYZxyz".into(),
"this_is_a_request_id".into(), "this_is_a_request_id".into(),
@ -192,7 +192,7 @@ mod test {
#[test] #[test]
fn secret_request_cancellation_serialization() { fn secret_request_cancellation_serialization() {
let content = RequestToDeviceEventContent::new( let content = ToDeviceRequestEventContent::new(
RequestAction::RequestCancellation, RequestAction::RequestCancellation,
"ABCDEFG".into(), "ABCDEFG".into(),
"randomly_generated_id_9573".into(), "randomly_generated_id_9573".into(),
@ -218,7 +218,7 @@ mod test {
assert_matches!( assert_matches!(
from_json_value(json).unwrap(), from_json_value(json).unwrap(),
RequestToDeviceEventContent { ToDeviceRequestEventContent {
action: RequestAction::Request( action: RequestAction::Request(
secret secret
), ),
@ -241,7 +241,7 @@ mod test {
assert_matches!( assert_matches!(
from_json_value(json).unwrap(), from_json_value(json).unwrap(),
RequestToDeviceEventContent { ToDeviceRequestEventContent {
action: RequestAction::RequestCancellation, action: RequestAction::RequestCancellation,
requesting_device_id, requesting_device_id,
request_id, request_id,
@ -262,7 +262,7 @@ mod test {
assert_matches!( assert_matches!(
from_json_value(json).unwrap(), from_json_value(json).unwrap(),
RequestToDeviceEventContent { ToDeviceRequestEventContent {
action: RequestAction::Request( action: RequestAction::Request(
SecretName::RecoveryKey SecretName::RecoveryKey
), ),
@ -283,8 +283,8 @@ mod test {
}); });
assert_matches!( assert_matches!(
from_json_value::<RequestToDeviceEventContent>(json).unwrap(), from_json_value::<ToDeviceRequestEventContent>(json).unwrap(),
RequestToDeviceEventContent { ToDeviceRequestEventContent {
action, action,
requesting_device_id, requesting_device_id,
request_id, request_id,

View File

@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.secret.send", kind = ToDevice)] #[ruma_event(type = "m.secret.send", kind = ToDevice)]
pub struct SendToDeviceEventContent { pub struct ToDeviceSendEventContent {
/// The ID of the request that this is a response to. /// The ID of the request that this is a response to.
pub request_id: String, pub request_id: String,
@ -20,7 +20,7 @@ pub struct SendToDeviceEventContent {
pub secret: String, pub secret: String,
} }
impl SendToDeviceEventContent { impl ToDeviceSendEventContent {
/// Creates a new `SecretSendEventContent` with the given request ID and secret. /// Creates a new `SecretSendEventContent` with the given request ID and secret.
pub fn new(request_id: String, secret: String) -> Self { pub fn new(request_id: String, secret: String) -> Self {
Self { request_id, secret } Self { request_id, secret }

View File

@ -1,4 +1,4 @@
use ruma_events::{room_key::RoomKeyToDeviceEventContent, ToDeviceEvent}; use ruma_events::{room_key::ToDeviceRoomKeyEventContent, ToDeviceEvent};
use ruma_identifiers::{room_id, user_id, EventEncryptionAlgorithm}; use ruma_identifiers::{room_id, user_id, EventEncryptionAlgorithm};
use serde_json::{json, to_value as to_json_value}; use serde_json::{json, to_value as to_json_value};
@ -6,7 +6,7 @@ use serde_json::{json, to_value as to_json_value};
fn serialization() { fn serialization() {
let ev = ToDeviceEvent { let ev = ToDeviceEvent {
sender: user_id!("@example:example.org"), sender: user_id!("@example:example.org"),
content: RoomKeyToDeviceEventContent::new( content: ToDeviceRoomKeyEventContent::new(
EventEncryptionAlgorithm::MegolmV1AesSha2, EventEncryptionAlgorithm::MegolmV1AesSha2,
room_id!("!testroomid:example.org"), room_id!("!testroomid:example.org"),
"SessId".into(), "SessId".into(),