diff --git a/crates/ruma-events-macros/src/event_enum.rs b/crates/ruma-events-macros/src/event_enum.rs index 530087db..0186913a 100644 --- a/crates/ruma-events-macros/src/event_enum.rs +++ b/crates/ruma-events-macros/src/event_enum.rs @@ -688,10 +688,6 @@ fn marker_traits(kind: &EventKind, ruma_events: &TokenStream) -> TokenStream { #[automatically_derived] impl #ruma_events::BasicEventContent for #ident {} }, - EventKind::BasicToDevice => quote! { - #[automatically_derived] - impl #ruma_events::BasicEventContent for #ident {} - }, _ => TokenStream::new(), } } diff --git a/crates/ruma-events-macros/src/event_parse.rs b/crates/ruma-events-macros/src/event_parse.rs index b289e702..8097e096 100644 --- a/crates/ruma-events-macros/src/event_parse.rs +++ b/crates/ruma-events-macros/src/event_parse.rs @@ -68,7 +68,6 @@ pub enum EventKind { Ephemeral, Message, State, - BasicToDevice, ToDevice, Redaction, Presence, @@ -82,7 +81,6 @@ impl fmt::Display for EventKind { EventKind::Ephemeral => write!(f, "EphemeralRoomEvent"), EventKind::Message => write!(f, "MessageEvent"), EventKind::State => write!(f, "StateEvent"), - EventKind::BasicToDevice => write!(f, "BasicToDeviceEvent"), EventKind::ToDevice => write!(f, "ToDeviceEvent"), EventKind::Redaction => write!(f, "RedactionEvent"), EventKind::Presence => write!(f, "PresenceEvent"), @@ -140,14 +138,13 @@ impl Parse for EventKind { "EphemeralRoom" => EventKind::Ephemeral, "Message" => EventKind::Message, "State" => EventKind::State, - "BasicToDevice" => EventKind::BasicToDevice, "ToDevice" => EventKind::ToDevice, id => { return Err(syn::Error::new( input.span(), format!( "valid event kinds are GlobalAccountData, RoomAccountData, EphemeralRoom, \ - Message, State, BasicToDevice, ToDevice found `{}`", + Message, State, ToDevice found `{}`", id ), )); @@ -179,7 +176,6 @@ pub fn to_kind_variation(ident: &Ident) -> Option<(EventKind, EventKindVariation "RedactedStrippedStateEvent" => { Some((EventKind::State, EventKindVariation::RedactedStripped)) } - "BasicToDeviceEvent" => Some((EventKind::BasicToDevice, EventKindVariation::Full)), "ToDeviceEvent" => Some((EventKind::ToDevice, EventKindVariation::Full)), "PresenceEvent" => Some((EventKind::Presence, EventKindVariation::Full)), "RedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Full)), diff --git a/crates/ruma-events/CHANGELOG.md b/crates/ruma-events/CHANGELOG.md index 2099184c..0fc168d6 100644 --- a/crates/ruma-events/CHANGELOG.md +++ b/crates/ruma-events/CHANGELOG.md @@ -42,7 +42,8 @@ Breaking changes: ``` * Add `tag::TagName` type and use it for `tag::Tags` * Move `FullyRead` from `EphemeralRoom` enum to `RoomAccountData` enum -* Split `Basic` enum into `GlobalAccountData`, `RoomAccountData` and `BasicToDevice` enums +* Split `Basic` enum into `GlobalAccountData` and `RoomAccountData` enums + * Remove `DummyEvent`, `DummyEventContent`, `RoomKeyEvent`, `RoomKeyEventContent` Improvements: diff --git a/crates/ruma-events/src/dummy.rs b/crates/ruma-events/src/dummy.rs index 06b6fa2f..66c6eefa 100644 --- a/crates/ruma-events/src/dummy.rs +++ b/crates/ruma-events/src/dummy.rs @@ -3,54 +3,7 @@ use ruma_events_macros::BasicEventContent; use serde::{Deserialize, Serialize}; -use crate::BasicToDeviceEvent; - -/// This event type is used to indicate new Olm sessions for end-to-end encryption. -/// -/// Typically it is encrypted as an *m.room.encrypted* event, then sent as a to-device event. -/// -/// The event does not have any content associated with it. The sending client is expected to -/// send a key share request shortly after this message, causing the receiving client to process -/// this *m.dummy* event as the most recent event and using the keyshare request to set up the -/// session. The keyshare request and *m.dummy* combination should result in the original -/// sending client receiving keys over the newly established session. -pub type DummyEvent = BasicToDeviceEvent; - /// The payload for `DummyEvent`. #[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] #[ruma_event(type = "m.dummy")] -pub struct DummyEventContent {} - -/// The to-device version of the payload for the `DummyEvent`. -pub type DummyToDeviceEventContent = DummyEventContent; - -#[cfg(test)] -mod tests { - use ruma_serde::Raw; - use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; - - use super::{DummyEvent, DummyEventContent}; - - #[test] - fn serialization() { - let dummy_event = DummyEvent { content: DummyEventContent {} }; - let actual = to_json_value(dummy_event).unwrap(); - - let expected = json!({ - "content": {}, - "type": "m.dummy" - }); - - assert_eq!(actual, expected); - } - - #[test] - fn deserialization() { - let json = json!({ - "content": {}, - "type": "m.dummy" - }); - - assert!(from_json_value::>(json).unwrap().deserialize().is_ok()); - } -} +pub struct DummyToDeviceEventContent {} diff --git a/crates/ruma-events/src/enums.rs b/crates/ruma-events/src/enums.rs index db646960..aa4fee98 100644 --- a/crates/ruma-events/src/enums.rs +++ b/crates/ruma-events/src/enums.rs @@ -98,15 +98,6 @@ event_enum! { ] } -event_enum! { - /// Any basic to-device event. - kind: BasicToDevice, - events: [ - "m.dummy", - "m.room_key", - ] -} - event_enum! { /// Any to-device event. kind: ToDevice, diff --git a/crates/ruma-events/src/event_kinds.rs b/crates/ruma-events/src/event_kinds.rs index 2510053b..99756a3b 100644 --- a/crates/ruma-events/src/event_kinds.rs +++ b/crates/ruma-events/src/event_kinds.rs @@ -317,14 +317,6 @@ pub struct RedactedStrippedStateEvent { pub state_key: String, } -/// A basic event sent using send-to-device event messaging – one that consists only of it's type -/// and the `content` object. -#[derive(Clone, Debug, Event)] -pub struct BasicToDeviceEvent { - /// Data specific to the event type. - pub content: C, -} - /// An event sent using send-to-device messaging. #[derive(Clone, Debug, Event)] pub struct ToDeviceEvent { diff --git a/crates/ruma-events/src/lib.rs b/crates/ruma-events/src/lib.rs index 6aa64c1b..92bdba1d 100644 --- a/crates/ruma-events/src/lib.rs +++ b/crates/ruma-events/src/lib.rs @@ -200,8 +200,8 @@ pub use self::{ }, error::{FromStrError, InvalidInput}, event_kinds::{ - BasicToDeviceEvent, EphemeralRoomEvent, GlobalAccountDataEvent, InitialStateEvent, - MessageEvent, RedactedMessageEvent, RedactedStateEvent, RedactedStrippedStateEvent, + EphemeralRoomEvent, GlobalAccountDataEvent, InitialStateEvent, MessageEvent, + RedactedMessageEvent, RedactedStateEvent, RedactedStrippedStateEvent, RedactedSyncMessageEvent, RedactedSyncStateEvent, RoomAccountDataEvent, StateEvent, StrippedStateEvent, SyncEphemeralRoomEvent, SyncMessageEvent, SyncStateEvent, ToDeviceEvent, diff --git a/crates/ruma-events/src/room_key.rs b/crates/ruma-events/src/room_key.rs index 0a35cfc6..ad66e26b 100644 --- a/crates/ruma-events/src/room_key.rs +++ b/crates/ruma-events/src/room_key.rs @@ -4,15 +4,10 @@ use ruma_events_macros::BasicEventContent; use ruma_identifiers::{EventEncryptionAlgorithm, RoomId}; use serde::{Deserialize, Serialize}; -use crate::BasicToDeviceEvent; - -/// Typically encrypted as an *m.room.encrypted* event, then sent as a to-device event. -pub type RoomKeyEvent = BasicToDeviceEvent; - /// The payload for `RoomKeyEvent`. #[derive(Clone, Debug, Deserialize, Serialize, BasicEventContent)] #[ruma_event(type = "m.room_key")] -pub struct RoomKeyEventContent { +pub struct RoomKeyToDeviceEventContent { /// The encryption algorithm the key in this event is to be used with. /// /// Must be `m.megolm.v1.aes-sha2`. @@ -28,26 +23,24 @@ pub struct RoomKeyEventContent { pub session_key: String, } -/// The to-device version of the payload for the `RoomKeyEvent`. -pub type RoomKeyToDeviceEventContent = RoomKeyEventContent; - #[cfg(test)] mod tests { - use ruma_identifiers::{room_id, EventEncryptionAlgorithm}; + use ruma_identifiers::{room_id, user_id, EventEncryptionAlgorithm}; use serde_json::{json, to_value as to_json_value}; - use super::RoomKeyEventContent; - use crate::BasicToDeviceEvent; + use super::RoomKeyToDeviceEventContent; + use crate::ToDeviceEvent; #[test] fn serialization() { - let ev = BasicToDeviceEvent { - content: RoomKeyEventContent { + let ev = ToDeviceEvent { + content: RoomKeyToDeviceEventContent { algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2, room_id: room_id!("!testroomid:example.org"), session_id: "SessId".into(), session_key: "SessKey".into(), }, + sender: user_id!("@user:example.org"), }; assert_eq!( @@ -60,6 +53,7 @@ mod tests { "session_id": "SessId", "session_key": "SessKey", }, + "sender": "@user:example.org", }) ); } diff --git a/crates/ruma-events/tests/to_device.rs b/crates/ruma-events/tests/to_device.rs index f3df7153..7c8cd514 100644 --- a/crates/ruma-events/tests/to_device.rs +++ b/crates/ruma-events/tests/to_device.rs @@ -1,4 +1,4 @@ -use ruma_events::{room_key::RoomKeyEventContent, AnyToDeviceEventContent, ToDeviceEvent}; +use ruma_events::{room_key::RoomKeyToDeviceEventContent, AnyToDeviceEventContent, ToDeviceEvent}; use ruma_identifiers::{room_id, user_id, EventEncryptionAlgorithm}; 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() { let ev = ToDeviceEvent { sender: user_id!("@example:example.org"), - content: AnyToDeviceEventContent::RoomKey(RoomKeyEventContent { + content: AnyToDeviceEventContent::RoomKey(RoomKeyToDeviceEventContent { algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2, room_id: room_id!("!testroomid:example.org"), session_id: "SessId".into(), diff --git a/crates/ruma-events/tests/ui/07-enum-sanity-check.rs b/crates/ruma-events/tests/ui/07-enum-sanity-check.rs index 3fe1d5f0..83ac5a53 100644 --- a/crates/ruma-events/tests/ui/07-enum-sanity-check.rs +++ b/crates/ruma-events/tests/ui/07-enum-sanity-check.rs @@ -6,10 +6,8 @@ event_enum! { events: [ "m.direct", #[cfg(test)] - "m.dummy", "m.ignored_user_list", "m.push_rules", - "m.room_key", #[cfg(any())] "m.ruma_test", ] diff --git a/crates/ruma-events/tests/ui/09-enum-invalid-kind.stderr b/crates/ruma-events/tests/ui/09-enum-invalid-kind.stderr index ace01a92..4a1cc655 100644 --- a/crates/ruma-events/tests/ui/09-enum-invalid-kind.stderr +++ b/crates/ruma-events/tests/ui/09-enum-invalid-kind.stderr @@ -1,4 +1,4 @@ -error: valid event kinds are GlobalAccountData, RoomAccountData, EphemeralRoom, Message, State, BasicToDevice, ToDevice found `NotReal` +error: valid event kinds are GlobalAccountData, RoomAccountData, EphemeralRoom, Message, State, ToDevice found `NotReal` --> $DIR/09-enum-invalid-kind.rs:4:18 | 4 | kind: NotReal, diff --git a/crates/ruma-federation-api/src/transactions/edu.rs b/crates/ruma-federation-api/src/transactions/edu.rs index 16f2236a..a6cb79b3 100644 --- a/crates/ruma-federation-api/src/transactions/edu.rs +++ b/crates/ruma-federation-api/src/transactions/edu.rs @@ -5,7 +5,7 @@ use std::collections::BTreeMap; use js_int::UInt; use ruma_common::{encryption::DeviceKeys, presence::PresenceState}; use ruma_events::{ - from_raw_json_value, receipt::Receipt, room_key::RoomKeyEventContent, EventType, + from_raw_json_value, receipt::Receipt, room_key::RoomKeyToDeviceEventContent, EventType, }; use ruma_identifiers::{DeviceIdBox, EventId, RoomId, UserId}; use serde::{de, Deserialize, Serialize}; @@ -258,7 +258,7 @@ pub struct DirectDeviceContent { /// The contents of the messages to be sent. These are arranged in a map /// of user IDs to a map of device IDs to message bodies. The device ID may /// also be *, meaning all known devices for the user. - pub messages: BTreeMap>, + pub messages: BTreeMap>, } impl DirectDeviceContent {