From 058d2bfa24ca7d15c3049868abd480405a4ce362 Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Fri, 14 May 2021 05:55:58 -0400 Subject: [PATCH] Add kind = ToDevice for all to device content --- crates/ruma-events-macros/src/event_enum.rs | 12 ++++++++++++ crates/ruma-events/src/dummy.rs | 2 +- crates/ruma-events/src/event_kinds.rs | 6 +++--- crates/ruma-events/src/forwarded_room_key.rs | 2 +- crates/ruma-events/src/key/verification/accept.rs | 2 +- crates/ruma-events/src/key/verification/cancel.rs | 2 +- crates/ruma-events/src/key/verification/done.rs | 2 +- crates/ruma-events/src/key/verification/key.rs | 2 +- crates/ruma-events/src/key/verification/mac.rs | 2 +- crates/ruma-events/src/key/verification/ready.rs | 2 +- crates/ruma-events/src/key/verification/request.rs | 2 +- crates/ruma-events/src/key/verification/start.rs | 2 +- crates/ruma-events/src/room_key.rs | 2 +- crates/ruma-events/src/room_key_request.rs | 2 +- crates/ruma-events/tests/to_device.rs | 2 +- 15 files changed, 28 insertions(+), 16 deletions(-) diff --git a/crates/ruma-events-macros/src/event_enum.rs b/crates/ruma-events-macros/src/event_enum.rs index 8ad580de..907d8028 100644 --- a/crates/ruma-events-macros/src/event_enum.rs +++ b/crates/ruma-events-macros/src/event_enum.rs @@ -680,6 +680,18 @@ fn marker_traits(kind: &EventKind, ruma_events: &TokenStream) -> TokenStream { #[automatically_derived] impl #ruma_events::EphemeralRoomEventContent for #ident {} }, + EventKind::GlobalAccountData => quote! { + #[automatically_derived] + impl #ruma_events::GlobalAccountDataEventContent for #ident {} + }, + EventKind::RoomAccountData => quote! { + #[automatically_derived] + impl #ruma_events::RoomAccountDataEventContent for #ident {} + }, + EventKind::ToDevice => quote! { + #[automatically_derived] + impl #ruma_events::ToDeviceEventContent for #ident {} + }, _ => TokenStream::new(), } } diff --git a/crates/ruma-events/src/dummy.rs b/crates/ruma-events/src/dummy.rs index f7f600ed..c532901b 100644 --- a/crates/ruma-events/src/dummy.rs +++ b/crates/ruma-events/src/dummy.rs @@ -15,5 +15,5 @@ use serde::{Deserialize, Serialize}; /// session. The keyshare request and *m.dummy* combination should result in the original /// sending client receiving keys over the newly established session. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.dummy")] +#[ruma_event(type = "m.dummy", kind = ToDevice)] pub struct DummyToDeviceEventContent {} diff --git a/crates/ruma-events/src/event_kinds.rs b/crates/ruma-events/src/event_kinds.rs index 73a0b961..56ca3f5e 100644 --- a/crates/ruma-events/src/event_kinds.rs +++ b/crates/ruma-events/src/event_kinds.rs @@ -3,9 +3,9 @@ use ruma_events_macros::Event; use ruma_identifiers::{EventId, RoomId, UserId}; use crate::{ - EphemeralRoomEventContent, EventContent, GlobalAccountDataEventContent, MessageEventContent, + EphemeralRoomEventContent, GlobalAccountDataEventContent, MessageEventContent, RedactedMessageEventContent, RedactedStateEventContent, RedactedSyncUnsigned, RedactedUnsigned, - RoomAccountDataEventContent, StateEventContent, Unsigned, + RoomAccountDataEventContent, StateEventContent, ToDeviceEventContent, Unsigned, }; /// A global account data event. @@ -318,7 +318,7 @@ pub struct RedactedStrippedStateEvent { /// An event sent using send-to-device messaging. #[derive(Clone, Debug, Event)] -pub struct ToDeviceEvent { +pub struct ToDeviceEvent { /// Data specific to the event type. pub content: C, diff --git a/crates/ruma-events/src/forwarded_room_key.rs b/crates/ruma-events/src/forwarded_room_key.rs index e7384020..74127e93 100644 --- a/crates/ruma-events/src/forwarded_room_key.rs +++ b/crates/ruma-events/src/forwarded_room_key.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; /// and convert it via `ForwardedRoomKeyToDeviceEventContent::from` / `.into()`. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[ruma_event(type = "m.forwarded_room_key")] +#[ruma_event(type = "m.forwarded_room_key", kind = ToDevice)] pub struct ForwardedRoomKeyToDeviceEventContent { /// The encryption algorithm the key in this event is to be used with. pub algorithm: EventEncryptionAlgorithm, diff --git a/crates/ruma-events/src/key/verification/accept.rs b/crates/ruma-events/src/key/verification/accept.rs index 84d22cce..d5202a2f 100644 --- a/crates/ruma-events/src/key/verification/accept.rs +++ b/crates/ruma-events/src/key/verification/accept.rs @@ -21,7 +21,7 @@ pub type AcceptEvent = MessageEvent; /// The payload for a to-device `AcceptEvent`. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.key.verification.accept")] +#[ruma_event(type = "m.key.verification.accept", kind = ToDevice)] pub struct AcceptToDeviceEventContent { /// An opaque identifier for the verification process. /// diff --git a/crates/ruma-events/src/key/verification/cancel.rs b/crates/ruma-events/src/key/verification/cancel.rs index 6b1c3492..e69f55db 100644 --- a/crates/ruma-events/src/key/verification/cancel.rs +++ b/crates/ruma-events/src/key/verification/cancel.rs @@ -16,7 +16,7 @@ pub type CancelEvent = MessageEvent; /// The payload for a to-device `CancelEvent`. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.key.verification.cancel")] +#[ruma_event(type = "m.key.verification.cancel", kind = ToDevice)] pub struct CancelToDeviceEventContent { /// The opaque identifier for the verification process/request. pub transaction_id: String, diff --git a/crates/ruma-events/src/key/verification/done.rs b/crates/ruma-events/src/key/verification/done.rs index bee354a8..7e691841 100644 --- a/crates/ruma-events/src/key/verification/done.rs +++ b/crates/ruma-events/src/key/verification/done.rs @@ -12,7 +12,7 @@ pub type DoneEvent = MessageEvent; /// The payload for a to-device `m.key.verification.done` event. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.key.verification.done")] +#[ruma_event(type = "m.key.verification.done", kind = ToDevice)] pub struct DoneToDeviceEventContent { /// An opaque identifier for the verification process. /// diff --git a/crates/ruma-events/src/key/verification/key.rs b/crates/ruma-events/src/key/verification/key.rs index 295e7b85..1a41634e 100644 --- a/crates/ruma-events/src/key/verification/key.rs +++ b/crates/ruma-events/src/key/verification/key.rs @@ -15,7 +15,7 @@ pub type KeyEvent = MessageEvent; /// The payload for a to-device `KeyEvent`. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.key.verification.key")] +#[ruma_event(type = "m.key.verification.key", kind = ToDevice)] pub struct KeyToDeviceEventContent { /// An opaque identifier for the verification process. /// diff --git a/crates/ruma-events/src/key/verification/mac.rs b/crates/ruma-events/src/key/verification/mac.rs index b20da69a..c4acc331 100644 --- a/crates/ruma-events/src/key/verification/mac.rs +++ b/crates/ruma-events/src/key/verification/mac.rs @@ -17,7 +17,7 @@ pub type MacEvent = MessageEvent; /// The payload for a to-device `MacEvent`. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.key.verification.mac")] +#[ruma_event(type = "m.key.verification.mac", kind = ToDevice)] pub struct MacToDeviceEventContent { /// An opaque identifier for the verification process. /// diff --git a/crates/ruma-events/src/key/verification/ready.rs b/crates/ruma-events/src/key/verification/ready.rs index 3b3d0b4c..5c401c96 100644 --- a/crates/ruma-events/src/key/verification/ready.rs +++ b/crates/ruma-events/src/key/verification/ready.rs @@ -12,7 +12,7 @@ pub type ReadyEvent = MessageEvent; /// The payload for a to-device `m.key.verification.ready` event. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.key.verification.ready")] +#[ruma_event(type = "m.key.verification.ready", kind = ToDevice)] pub struct ReadyToDeviceEventContent { /// The device ID which is initiating the request. pub from_device: DeviceIdBox, diff --git a/crates/ruma-events/src/key/verification/request.rs b/crates/ruma-events/src/key/verification/request.rs index 9f1659d1..71a3caaa 100644 --- a/crates/ruma-events/src/key/verification/request.rs +++ b/crates/ruma-events/src/key/verification/request.rs @@ -9,7 +9,7 @@ use super::VerificationMethod; /// The payload for `RequestEvent`. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.key.verification.request")] +#[ruma_event(type = "m.key.verification.request", kind = ToDevice)] pub struct RequestToDeviceEventContent { /// The device ID which is initiating the request. pub from_device: DeviceIdBox, diff --git a/crates/ruma-events/src/key/verification/start.rs b/crates/ruma-events/src/key/verification/start.rs index ec59dd5b..cbb6f366 100644 --- a/crates/ruma-events/src/key/verification/start.rs +++ b/crates/ruma-events/src/key/verification/start.rs @@ -23,7 +23,7 @@ pub type StartEvent = MessageEvent; /// The payload of a to-device *m.key.verification.start* event. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.key.verification.start")] +#[ruma_event(type = "m.key.verification.start", kind = ToDevice)] pub struct StartToDeviceEventContent { /// The device ID which is initiating the process. pub from_device: DeviceIdBox, diff --git a/crates/ruma-events/src/room_key.rs b/crates/ruma-events/src/room_key.rs index 07ff04b9..e25ca6f9 100644 --- a/crates/ruma-events/src/room_key.rs +++ b/crates/ruma-events/src/room_key.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; /// /// Typically encrypted as an *m.room.encrypted* event, then sent as a to-device event. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.room_key")] +#[ruma_event(type = "m.room_key", kind = ToDevice)] pub struct RoomKeyToDeviceEventContent { /// The encryption algorithm the key in this event is to be used with. /// diff --git a/crates/ruma-events/src/room_key_request.rs b/crates/ruma-events/src/room_key_request.rs index c718b8fb..3dd0ee4a 100644 --- a/crates/ruma-events/src/room_key_request.rs +++ b/crates/ruma-events/src/room_key_request.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; /// The payload for `RoomKeyRequestEvent`. #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] -#[ruma_event(type = "m.room_key_request")] +#[ruma_event(type = "m.room_key_request", kind = ToDevice)] pub struct RoomKeyRequestToDeviceEventContent { /// Whether this is a new key request or a cancellation of a previous request. pub action: Action, diff --git a/crates/ruma-events/tests/to_device.rs b/crates/ruma-events/tests/to_device.rs index 7c8cd514..4b5c8ae7 100644 --- a/crates/ruma-events/tests/to_device.rs +++ b/crates/ruma-events/tests/to_device.rs @@ -15,7 +15,7 @@ fn serialization() { }; assert_eq!( - to_json_value(ev).unwrap(), + to_json_value(&ev).unwrap(), json!({ "type": "m.room_key", "sender": "@example:example.org",