events: Add types for decrypted event payloads
This commit is contained in:
parent
090948e04f
commit
05e28f7422
@ -17,7 +17,7 @@ pub fn expand_event(input: DeriveInput) -> syn::Result<TokenStream> {
|
||||
|
||||
let ident = &input.ident;
|
||||
let (kind, var) = to_kind_variation(ident).ok_or_else(|| {
|
||||
syn::Error::new(Span::call_site(), "not a valid ruma event struct identifier")
|
||||
syn::Error::new_spanned(ident, "not a valid ruma event struct identifier")
|
||||
})?;
|
||||
|
||||
let fields: Vec<_> = if let Data::Struct(DataStruct { fields, .. }) = input.data.clone() {
|
||||
|
@ -313,8 +313,9 @@ fn generate_event_content_derives(
|
||||
EventKind::Message => Ok(quote! { MessageEventContent }),
|
||||
EventKind::State => Ok(quote! { StateEventContent }),
|
||||
EventKind::ToDevice => Ok(quote! { ToDeviceEventContent }),
|
||||
EventKind::Redaction => Err(syn::Error::new_spanned(ident, msg)),
|
||||
EventKind::Presence => Err(syn::Error::new_spanned(ident, msg)),
|
||||
EventKind::Redaction | EventKind::Presence | EventKind::Decrypted => {
|
||||
Err(syn::Error::new_spanned(ident, msg))
|
||||
}
|
||||
})
|
||||
.collect::<syn::Result<_>>()?;
|
||||
|
||||
|
@ -71,6 +71,7 @@ pub enum EventKind {
|
||||
ToDevice,
|
||||
Redaction,
|
||||
Presence,
|
||||
Decrypted,
|
||||
}
|
||||
|
||||
impl fmt::Display for EventKind {
|
||||
@ -84,6 +85,7 @@ impl fmt::Display for EventKind {
|
||||
EventKind::ToDevice => write!(f, "ToDeviceEvent"),
|
||||
EventKind::Redaction => write!(f, "RedactionEvent"),
|
||||
EventKind::Presence => write!(f, "PresenceEvent"),
|
||||
EventKind::Decrypted => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -203,6 +205,9 @@ pub fn to_kind_variation(ident: &Ident) -> Option<(EventKind, EventKindVariation
|
||||
"PresenceEvent" => Some((EventKind::Presence, EventKindVariation::Full)),
|
||||
"RedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Full)),
|
||||
"SyncRedactionEvent" => Some((EventKind::Redaction, EventKindVariation::Sync)),
|
||||
"DecryptedOlmV1Event" | "DecryptedMegolmV1Event" => {
|
||||
Some((EventKind::Decrypted, EventKindVariation::Full))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,7 @@ pub fn expand_event_type_enum(
|
||||
room.push(&event.events);
|
||||
}
|
||||
EventKind::ToDevice => to_device.push(&event.events),
|
||||
EventKind::Redaction => {}
|
||||
EventKind::Presence => {}
|
||||
EventKind::Redaction | EventKind::Presence | EventKind::Decrypted => {}
|
||||
}
|
||||
}
|
||||
let presence = vec![EventEnumEntry {
|
||||
|
@ -11,6 +11,14 @@ Breaking changes:
|
||||
* Remove `Custom` variant from `key::verification::accept::AcceptMethod` and
|
||||
`key::verification::start::StartMethod`.
|
||||
|
||||
Improvements:
|
||||
|
||||
* Add types for decrypted `m.room.encryption` event payloads (`DecryptedOlmV1Event`,
|
||||
`DecryptedMegolmV1Event`)
|
||||
* Currently, these don't have corresponding enums (and they might never get ones), instead to
|
||||
represent a decrypted event payload with an unknown event type use `AnyMessageEventContent` for
|
||||
the generic parameter
|
||||
|
||||
# 0.22.2
|
||||
|
||||
Improvements:
|
||||
|
@ -3,6 +3,7 @@
|
||||
use ruma_common::MilliSecondsSinceUnixEpoch;
|
||||
use ruma_events_macros::Event;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
EphemeralRoomEventContent, GlobalAccountDataEventContent, MessageEventContent,
|
||||
@ -327,3 +328,39 @@ pub struct ToDeviceEvent<C: ToDeviceEventContent> {
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
}
|
||||
|
||||
/// The decrypted payload of an `m.olm.v1.curve25519-aes-sha2` event.
|
||||
#[derive(Clone, Debug, Event)]
|
||||
pub struct DecryptedOlmV1Event<C: MessageEventContent> {
|
||||
/// Data specific to the event type.
|
||||
pub content: C,
|
||||
|
||||
/// The fully-qualified ID of the user who sent this event.
|
||||
pub sender: UserId,
|
||||
|
||||
/// The fully-qualified ID of the intended recipient this event.
|
||||
pub recipient: UserId,
|
||||
|
||||
/// The recipient's ed25519 key.
|
||||
pub recipient_keys: OlmV1Keys,
|
||||
|
||||
/// The sender's ed25519 key.
|
||||
pub keys: OlmV1Keys,
|
||||
}
|
||||
|
||||
/// Public keys used for an `m.olm.v1.curve25519-aes-sha2` event.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct OlmV1Keys {
|
||||
/// An ed25519 key.
|
||||
ed25519: String,
|
||||
}
|
||||
|
||||
/// The decrypted payload of an `m.megolm.v1.aes-sha2` event.
|
||||
#[derive(Clone, Debug, Event)]
|
||||
pub struct DecryptedMegolmV1Event<C: MessageEventContent> {
|
||||
/// Data specific to the event type.
|
||||
pub content: C,
|
||||
|
||||
/// The ID of the room associated with the event.
|
||||
pub room_id: RoomId,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user