events: Remove BasicToDevice enum
This commit is contained in:
parent
8d8ca81e04
commit
7faa59be6b
@ -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(),
|
||||
}
|
||||
}
|
||||
|
@ -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)),
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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<DummyEventContent>;
|
||||
|
||||
/// 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::<Raw<DummyEvent>>(json).unwrap().deserialize().is_ok());
|
||||
}
|
||||
}
|
||||
pub struct DummyToDeviceEventContent {}
|
||||
|
@ -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,
|
||||
|
@ -317,14 +317,6 @@ pub struct RedactedStrippedStateEvent<C: RedactedStateEventContent> {
|
||||
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<C: BasicEventContent> {
|
||||
/// Data specific to the event type.
|
||||
pub content: C,
|
||||
}
|
||||
|
||||
/// An event sent using send-to-device messaging.
|
||||
#[derive(Clone, Debug, Event)]
|
||||
pub struct ToDeviceEvent<C: EventContent> {
|
||||
|
@ -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,
|
||||
|
@ -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<RoomKeyEventContent>;
|
||||
|
||||
/// 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",
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -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(),
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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,
|
||||
|
@ -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<UserId, BTreeMap<DeviceIdBox, RoomKeyEventContent>>,
|
||||
pub messages: BTreeMap<UserId, BTreeMap<DeviceIdBox, RoomKeyToDeviceEventContent>>,
|
||||
}
|
||||
|
||||
impl DirectDeviceContent {
|
||||
|
Loading…
x
Reference in New Issue
Block a user