Add kind = ToDevice for all to device content

This commit is contained in:
Devin Ragotzy 2021-05-14 05:55:58 -04:00 committed by Jonas Platte
parent b6558c64a0
commit 058d2bfa24
15 changed files with 28 additions and 16 deletions

View File

@ -680,6 +680,18 @@ fn marker_traits(kind: &EventKind, ruma_events: &TokenStream) -> TokenStream {
#[automatically_derived] #[automatically_derived]
impl #ruma_events::EphemeralRoomEventContent for #ident {} 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(), _ => TokenStream::new(),
} }
} }

View File

@ -15,5 +15,5 @@ use serde::{Deserialize, Serialize};
/// session. The keyshare request and *m.dummy* combination should result in the original /// session. The keyshare request and *m.dummy* combination should result in the original
/// sending client receiving keys over the newly established session. /// sending client receiving keys over the newly established session.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[ruma_event(type = "m.dummy")] #[ruma_event(type = "m.dummy", kind = ToDevice)]
pub struct DummyToDeviceEventContent {} pub struct DummyToDeviceEventContent {}

View File

@ -3,9 +3,9 @@ use ruma_events_macros::Event;
use ruma_identifiers::{EventId, RoomId, UserId}; use ruma_identifiers::{EventId, RoomId, UserId};
use crate::{ use crate::{
EphemeralRoomEventContent, EventContent, GlobalAccountDataEventContent, MessageEventContent, EphemeralRoomEventContent, GlobalAccountDataEventContent, MessageEventContent,
RedactedMessageEventContent, RedactedStateEventContent, RedactedSyncUnsigned, RedactedUnsigned, RedactedMessageEventContent, RedactedStateEventContent, RedactedSyncUnsigned, RedactedUnsigned,
RoomAccountDataEventContent, StateEventContent, Unsigned, RoomAccountDataEventContent, StateEventContent, ToDeviceEventContent, Unsigned,
}; };
/// A global account data event. /// A global account data event.
@ -318,7 +318,7 @@ pub struct RedactedStrippedStateEvent<C: RedactedStateEventContent> {
/// An event sent using send-to-device messaging. /// An event sent using send-to-device messaging.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct ToDeviceEvent<C: EventContent> { pub struct ToDeviceEvent<C: ToDeviceEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
pub content: C, pub content: C,

View File

@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
/// and convert it via `ForwardedRoomKeyToDeviceEventContent::from` / `.into()`. /// and convert it via `ForwardedRoomKeyToDeviceEventContent::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")] #[ruma_event(type = "m.forwarded_room_key", kind = ToDevice)]
pub struct ForwardedRoomKeyToDeviceEventContent { pub struct ForwardedRoomKeyToDeviceEventContent {
/// 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,

View File

@ -21,7 +21,7 @@ pub type AcceptEvent = MessageEvent<AcceptEventContent>;
/// The payload for a to-device `AcceptEvent`. /// The payload for a to-device `AcceptEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[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 { pub struct AcceptToDeviceEventContent {
/// An opaque identifier for the verification process. /// An opaque identifier for the verification process.
/// ///

View File

@ -16,7 +16,7 @@ pub type CancelEvent = MessageEvent<CancelEventContent>;
/// The payload for a to-device `CancelEvent`. /// The payload for a to-device `CancelEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[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 { pub struct CancelToDeviceEventContent {
/// The opaque identifier for the verification process/request. /// The opaque identifier for the verification process/request.
pub transaction_id: String, pub transaction_id: String,

View File

@ -12,7 +12,7 @@ pub type DoneEvent = MessageEvent<DoneEventContent>;
/// The payload for a to-device `m.key.verification.done` event. /// The payload for a to-device `m.key.verification.done` event.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[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 { pub struct DoneToDeviceEventContent {
/// An opaque identifier for the verification process. /// An opaque identifier for the verification process.
/// ///

View File

@ -15,7 +15,7 @@ pub type KeyEvent = MessageEvent<KeyEventContent>;
/// The payload for a to-device `KeyEvent`. /// The payload for a to-device `KeyEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[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 { pub struct KeyToDeviceEventContent {
/// An opaque identifier for the verification process. /// An opaque identifier for the verification process.
/// ///

View File

@ -17,7 +17,7 @@ pub type MacEvent = MessageEvent<MacEventContent>;
/// The payload for a to-device `MacEvent`. /// The payload for a to-device `MacEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[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 { pub struct MacToDeviceEventContent {
/// An opaque identifier for the verification process. /// An opaque identifier for the verification process.
/// ///

View File

@ -12,7 +12,7 @@ pub type ReadyEvent = MessageEvent<ReadyEventContent>;
/// The payload for a to-device `m.key.verification.ready` event. /// The payload for a to-device `m.key.verification.ready` event.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[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 { pub struct ReadyToDeviceEventContent {
/// The device ID which is initiating the request. /// The device ID which is initiating the request.
pub from_device: DeviceIdBox, pub from_device: DeviceIdBox,

View File

@ -9,7 +9,7 @@ use super::VerificationMethod;
/// The payload for `RequestEvent`. /// The payload for `RequestEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[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 { pub struct RequestToDeviceEventContent {
/// The device ID which is initiating the request. /// The device ID which is initiating the request.
pub from_device: DeviceIdBox, pub from_device: DeviceIdBox,

View File

@ -23,7 +23,7 @@ pub type StartEvent = MessageEvent<StartEventContent>;
/// The payload of a to-device *m.key.verification.start* event. /// The payload of a to-device *m.key.verification.start* event.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[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 { pub struct StartToDeviceEventContent {
/// The device ID which is initiating the process. /// The device ID which is initiating the process.
pub from_device: DeviceIdBox, pub from_device: DeviceIdBox,

View File

@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
/// ///
/// Typically encrypted as an *m.room.encrypted* event, then sent as a to-device event. /// Typically encrypted as an *m.room.encrypted* event, then sent as a to-device event.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[ruma_event(type = "m.room_key")] #[ruma_event(type = "m.room_key", kind = ToDevice)]
pub struct RoomKeyToDeviceEventContent { pub struct RoomKeyToDeviceEventContent {
/// 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.
/// ///

View File

@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
/// The payload for `RoomKeyRequestEvent`. /// The payload for `RoomKeyRequestEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[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 { pub struct RoomKeyRequestToDeviceEventContent {
/// 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,

View File

@ -15,7 +15,7 @@ fn serialization() {
}; };
assert_eq!( assert_eq!(
to_json_value(ev).unwrap(), to_json_value(&ev).unwrap(),
json!({ json!({
"type": "m.room_key", "type": "m.room_key",
"sender": "@example:example.org", "sender": "@example:example.org",