events: Rename MessageEvent to MessageLikeEvent

This commit is contained in:
Kévin Commaille 2022-02-22 20:06:36 +01:00 committed by GitHub
parent f78ae4ddde
commit 771f437d9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 179 additions and 162 deletions

View File

@ -6,7 +6,7 @@ pub mod v3 {
//! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidsendeventtypetxnid //! [spec]: https://spec.matrix.org/v1.2/client-server-api/#put_matrixclientv3roomsroomidsendeventtypetxnid
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_events::{AnyMessageEventContent, MessageEventContent}; use ruma_events::{AnyMessageLikeEventContent, MessageLikeEventContent};
use ruma_identifiers::{EventId, RoomId, TransactionId}; use ruma_identifiers::{EventId, RoomId, TransactionId};
use ruma_serde::Raw; use ruma_serde::Raw;
use serde_json::value::to_raw_value as to_raw_json_value; use serde_json::value::to_raw_value as to_raw_json_value;
@ -42,7 +42,7 @@ pub mod v3 {
/// The event content to send. /// The event content to send.
#[ruma_api(body)] #[ruma_api(body)]
pub body: Raw<AnyMessageEventContent>, pub body: Raw<AnyMessageLikeEventContent>,
} }
response: { response: {
@ -60,7 +60,7 @@ pub mod v3 {
/// ///
/// Since `Request` stores the request body in serialized form, this function can fail if /// Since `Request` stores the request body in serialized form, this function can fail if
/// `T`s [`Serialize`][serde::Serialize] implementation can fail. /// `T`s [`Serialize`][serde::Serialize] implementation can fail.
pub fn new<T: MessageEventContent>( pub fn new<T: MessageLikeEventContent>(
room_id: &'a RoomId, room_id: &'a RoomId,
txn_id: &'a TransactionId, txn_id: &'a TransactionId,
content: &'a T, content: &'a T,
@ -79,7 +79,7 @@ pub mod v3 {
room_id: &'a RoomId, room_id: &'a RoomId,
txn_id: &'a TransactionId, txn_id: &'a TransactionId,
event_type: &'a str, event_type: &'a str,
body: Raw<AnyMessageEventContent>, body: Raw<AnyMessageLikeEventContent>,
) -> Self { ) -> Self {
Self { room_id, event_type, txn_id, body } Self { room_id, event_type, txn_id, body }
} }

View File

@ -51,7 +51,7 @@ pub fn expand_event(input: DeriveInput) -> syn::Result<TokenStream> {
res.extend(expand_sync_from_into_full(&input, kind, var, &fields, &ruma_events)); res.extend(expand_sync_from_into_full(&input, kind, var, &fields, &ruma_events));
} }
if matches!(kind, EventKind::Message | EventKind::State) if matches!(kind, EventKind::MessageLike | EventKind::State)
&& matches!(var, EventKindVariation::Full | EventKindVariation::Sync) && matches!(var, EventKindVariation::Full | EventKindVariation::Sync)
{ {
res.extend(expand_redact_event(&input, kind, var, &fields, &ruma_events)); res.extend(expand_redact_event(&input, kind, var, &fields, &ruma_events));

View File

@ -1,4 +1,4 @@
//! Implementations of the MessageEventContent and StateEventContent derive macro. //! Implementations of the MessageLikeEventContent and StateEventContent derive macro.
use std::borrow::Cow; use std::borrow::Cow;
@ -145,7 +145,7 @@ pub fn expand_event_content(
} }
}; };
// We only generate redacted content structs for state and message events // We only generate redacted content structs for state and message-like events
let redacted_event_content = needs_redacted(&content_attr, event_kind) let redacted_event_content = needs_redacted(&content_attr, event_kind)
.then(|| generate_redacted_event_content(input, event_type, ruma_events, event_kind)) .then(|| generate_redacted_event_content(input, event_type, ruma_events, event_kind))
.transpose()?; .transpose()?;
@ -262,9 +262,9 @@ fn generate_redacted_event_content(
generate_event_content_impl(&redacted_ident, event_type, ruma_events); generate_event_content_impl(&redacted_ident, event_type, ruma_events);
let marker_trait_impl = match event_kind { let marker_trait_impl = match event_kind {
Some(EventKind::Message) => quote! { Some(EventKind::MessageLike) => quote! {
#[automatically_derived] #[automatically_derived]
impl #ruma_events::RedactedMessageEventContent for #redacted_ident {} impl #ruma_events::RedactedMessageLikeEventContent for #redacted_ident {}
}, },
Some(EventKind::State) => quote! { Some(EventKind::State) => quote! {
#[automatically_derived] #[automatically_derived]
@ -391,14 +391,14 @@ fn generate_marker_trait_impl(
EventKind::GlobalAccountData => quote! { GlobalAccountDataEventContent }, EventKind::GlobalAccountData => quote! { GlobalAccountDataEventContent },
EventKind::RoomAccountData => quote! { RoomAccountDataEventContent }, EventKind::RoomAccountData => quote! { RoomAccountDataEventContent },
EventKind::Ephemeral => quote! { EphemeralRoomEventContent }, EventKind::Ephemeral => quote! { EphemeralRoomEventContent },
EventKind::Message => quote! { MessageEventContent }, EventKind::MessageLike => quote! { MessageLikeEventContent },
EventKind::State => quote! { StateEventContent }, EventKind::State => quote! { StateEventContent },
EventKind::ToDevice => quote! { ToDeviceEventContent }, EventKind::ToDevice => quote! { ToDeviceEventContent },
EventKind::RoomRedaction | EventKind::Presence | EventKind::Decrypted => { EventKind::RoomRedaction | EventKind::Presence | EventKind::Decrypted => {
return Err(syn::Error::new_spanned( return Err(syn::Error::new_spanned(
ident, ident,
"valid event kinds are GlobalAccountData, RoomAccountData, \ "valid event kinds are GlobalAccountData, RoomAccountData, \
EphemeralRoom, Message, State, ToDevice", EphemeralRoom, MessageLike, State, ToDevice",
)); ));
} }
}; };
@ -451,7 +451,7 @@ fn generate_static_event_content_impl(
EventKind::GlobalAccountData => quote! { GlobalAccountData }, EventKind::GlobalAccountData => quote! { GlobalAccountData },
EventKind::RoomAccountData => quote! { RoomAccountData }, EventKind::RoomAccountData => quote! { RoomAccountData },
EventKind::Ephemeral => quote! { EphemeralRoomData }, EventKind::Ephemeral => quote! { EphemeralRoomData },
EventKind::Message => quote! { Message { redacted: #redacted } }, EventKind::MessageLike => quote! { MessageLike { redacted: #redacted } },
EventKind::State => quote! { State { redacted: #redacted } }, EventKind::State => quote! { State { redacted: #redacted } },
EventKind::ToDevice => quote! { ToDevice }, EventKind::ToDevice => quote! { ToDevice },
EventKind::RoomRedaction | EventKind::Presence | EventKind::Decrypted => { EventKind::RoomRedaction | EventKind::Presence | EventKind::Decrypted => {
@ -472,5 +472,5 @@ fn needs_redacted(input: &[MetaAttrs], event_kind: Option<EventKind>) -> bool {
// redacted struct also. If no `custom_redacted` attrs are found the content // redacted struct also. If no `custom_redacted` attrs are found the content
// needs a redacted struct generated. // needs a redacted struct generated.
!input.iter().any(|a| a.is_custom()) !input.iter().any(|a| a.is_custom())
&& matches!(event_kind, Some(EventKind::Message) | Some(EventKind::State)) && matches!(event_kind, Some(EventKind::MessageLike) | Some(EventKind::State))
} }

View File

@ -30,7 +30,7 @@ pub fn expand_event_enums(input: &EventEnumDecl) -> syn::Result<TokenStream> {
res.extend(expand_event_enum(kind, V::Full, events, attrs, variants, ruma_events)); res.extend(expand_event_enum(kind, V::Full, events, attrs, variants, ruma_events));
res.extend(expand_content_enum(kind, events, attrs, variants, ruma_events)); res.extend(expand_content_enum(kind, events, attrs, variants, ruma_events));
if matches!(kind, EventKind::Ephemeral | EventKind::Message | EventKind::State) { if matches!(kind, EventKind::Ephemeral | EventKind::MessageLike | EventKind::State) {
res.extend(expand_event_enum(kind, V::Sync, events, attrs, variants, ruma_events)); res.extend(expand_event_enum(kind, V::Sync, events, attrs, variants, ruma_events));
res.extend(expand_from_full_event(kind, V::Full, variants)); res.extend(expand_from_full_event(kind, V::Full, variants));
res.extend(expand_into_full_event(kind, V::Sync, variants, ruma_events)); res.extend(expand_into_full_event(kind, V::Sync, variants, ruma_events));
@ -41,7 +41,7 @@ pub fn expand_event_enums(input: &EventEnumDecl) -> syn::Result<TokenStream> {
res.extend(expand_event_enum(kind, V::Initial, events, attrs, variants, ruma_events)); res.extend(expand_event_enum(kind, V::Initial, events, attrs, variants, ruma_events));
} }
if matches!(kind, EventKind::Message | EventKind::State) { if matches!(kind, EventKind::MessageLike | EventKind::State) {
res.extend(expand_event_enum(kind, V::Redacted, events, attrs, variants, ruma_events)); res.extend(expand_event_enum(kind, V::Redacted, events, attrs, variants, ruma_events));
res.extend(expand_event_enum(kind, V::RedactedSync, events, attrs, variants, ruma_events)); res.extend(expand_event_enum(kind, V::RedactedSync, events, attrs, variants, ruma_events));
res.extend(expand_redact(kind, V::Full, variants, ruma_events)); res.extend(expand_redact(kind, V::Full, variants, ruma_events));
@ -407,7 +407,7 @@ fn expand_possibly_redacted_enum(
fn expand_marker_trait_impl(kind: EventKind, ruma_events: &TokenStream) -> TokenStream { fn expand_marker_trait_impl(kind: EventKind, ruma_events: &TokenStream) -> TokenStream {
let marker_trait = match kind { let marker_trait = match kind {
EventKind::State => quote! { StateEventContent }, EventKind::State => quote! { StateEventContent },
EventKind::Message => quote! { MessageEventContent }, EventKind::MessageLike => quote! { MessageLikeEventContent },
EventKind::Ephemeral => quote! { EphemeralRoomEventContent }, EventKind::Ephemeral => quote! { EphemeralRoomEventContent },
EventKind::GlobalAccountData => quote! { GlobalAccountDataEventContent }, EventKind::GlobalAccountData => quote! { GlobalAccountDataEventContent },
EventKind::RoomAccountData => quote! { RoomAccountDataEventContent }, EventKind::RoomAccountData => quote! { RoomAccountDataEventContent },

View File

@ -80,7 +80,7 @@ pub enum EventKind {
GlobalAccountData, GlobalAccountData,
RoomAccountData, RoomAccountData,
Ephemeral, Ephemeral,
Message, MessageLike,
State, State,
ToDevice, ToDevice,
RoomRedaction, RoomRedaction,
@ -94,7 +94,7 @@ impl fmt::Display for EventKind {
EventKind::GlobalAccountData => write!(f, "GlobalAccountDataEvent"), EventKind::GlobalAccountData => write!(f, "GlobalAccountDataEvent"),
EventKind::RoomAccountData => write!(f, "RoomAccountDataEvent"), EventKind::RoomAccountData => write!(f, "RoomAccountDataEvent"),
EventKind::Ephemeral => write!(f, "EphemeralRoomEvent"), EventKind::Ephemeral => write!(f, "EphemeralRoomEvent"),
EventKind::Message => write!(f, "MessageEvent"), EventKind::MessageLike => write!(f, "MessageLikeEvent"),
EventKind::State => write!(f, "StateEvent"), EventKind::State => write!(f, "StateEvent"),
EventKind::ToDevice => write!(f, "ToDeviceEvent"), EventKind::ToDevice => write!(f, "ToDeviceEvent"),
EventKind::RoomRedaction => write!(f, "RoomRedactionEvent"), EventKind::RoomRedaction => write!(f, "RoomRedactionEvent"),
@ -130,8 +130,11 @@ impl EventKind {
match (self, var) { match (self, var) {
(_, V::Full) (_, V::Full)
| (Self::Message | Self::RoomRedaction | Self::State | Self::Ephemeral, V::Sync) | (Self::MessageLike | Self::RoomRedaction | Self::State | Self::Ephemeral, V::Sync)
| (Self::Message | Self::RoomRedaction | Self::State, V::Redacted | V::RedactedSync) | (
Self::MessageLike | Self::RoomRedaction | Self::State,
V::Redacted | V::RedactedSync,
)
| (Self::State, V::Stripped | V::Initial) => Some(format_ident!("{}{}", var, self)), | (Self::State, V::Stripped | V::Initial) => Some(format_ident!("{}{}", var, self)),
_ => None, _ => None,
} }
@ -160,7 +163,7 @@ impl Parse for EventKind {
"GlobalAccountData" => EventKind::GlobalAccountData, "GlobalAccountData" => EventKind::GlobalAccountData,
"RoomAccountData" => EventKind::RoomAccountData, "RoomAccountData" => EventKind::RoomAccountData,
"EphemeralRoom" => EventKind::Ephemeral, "EphemeralRoom" => EventKind::Ephemeral,
"Message" => EventKind::Message, "MessageLike" => EventKind::MessageLike,
"State" => EventKind::State, "State" => EventKind::State,
"ToDevice" => EventKind::ToDevice, "ToDevice" => EventKind::ToDevice,
id => { id => {
@ -168,7 +171,7 @@ impl Parse for EventKind {
ident, ident,
format!( format!(
"valid event kinds are GlobalAccountData, RoomAccountData, EphemeralRoom, \ "valid event kinds are GlobalAccountData, RoomAccountData, EphemeralRoom, \
Message, State, ToDevice found `{}`", MessageLike, State, ToDevice found `{}`",
id id
), ),
)); ));
@ -187,10 +190,12 @@ pub fn to_kind_variation(ident: &Ident) -> Option<(EventKind, EventKindVariation
"RoomAccountDataEvent" => Some((EventKind::RoomAccountData, EventKindVariation::Full)), "RoomAccountDataEvent" => Some((EventKind::RoomAccountData, EventKindVariation::Full)),
"EphemeralRoomEvent" => Some((EventKind::Ephemeral, EventKindVariation::Full)), "EphemeralRoomEvent" => Some((EventKind::Ephemeral, EventKindVariation::Full)),
"SyncEphemeralRoomEvent" => Some((EventKind::Ephemeral, EventKindVariation::Sync)), "SyncEphemeralRoomEvent" => Some((EventKind::Ephemeral, EventKindVariation::Sync)),
"MessageEvent" => Some((EventKind::Message, EventKindVariation::Full)), "MessageLikeEvent" => Some((EventKind::MessageLike, EventKindVariation::Full)),
"SyncMessageEvent" => Some((EventKind::Message, EventKindVariation::Sync)), "SyncMessageLikeEvent" => Some((EventKind::MessageLike, EventKindVariation::Sync)),
"RedactedMessageEvent" => Some((EventKind::Message, EventKindVariation::Redacted)), "RedactedMessageLikeEvent" => Some((EventKind::MessageLike, EventKindVariation::Redacted)),
"RedactedSyncMessageEvent" => Some((EventKind::Message, EventKindVariation::RedactedSync)), "RedactedSyncMessageLikeEvent" => {
Some((EventKind::MessageLike, EventKindVariation::RedactedSync))
}
"StateEvent" => Some((EventKind::State, EventKindVariation::Full)), "StateEvent" => Some((EventKind::State, EventKindVariation::Full)),
"SyncStateEvent" => Some((EventKind::State, EventKindVariation::Sync)), "SyncStateEvent" => Some((EventKind::State, EventKindVariation::Sync)),
"StrippedStateEvent" => Some((EventKind::State, EventKindVariation::Stripped)), "StrippedStateEvent" => Some((EventKind::State, EventKindVariation::Stripped)),

View File

@ -22,7 +22,7 @@ pub fn expand_event_type_enum(
EventKind::GlobalAccountData => global_account.push(&event.events), EventKind::GlobalAccountData => global_account.push(&event.events),
EventKind::RoomAccountData => room_account.push(&event.events), EventKind::RoomAccountData => room_account.push(&event.events),
EventKind::Ephemeral => ephemeral.push(&event.events), EventKind::Ephemeral => ephemeral.push(&event.events),
EventKind::Message => { EventKind::MessageLike => {
message.push(&event.events); message.push(&event.events);
room.push(&event.events); room.push(&event.events);
} }
@ -62,7 +62,7 @@ pub fn expand_event_type_enum(
let (message_event_types, message_str_ev_types) = generate_variants(&message)?; let (message_event_types, message_str_ev_types) = generate_variants(&message)?;
let message = generate_enum( let message = generate_enum(
format_ident!("MessageEventType"), format_ident!("MessageLikeEventType"),
message_str_ev_types, message_str_ev_types,
message_event_types, message_event_types,
&ruma_serde, &ruma_serde,

View File

@ -1,7 +1,7 @@
use crate::event_parse::{EventKind, EventKindVariation}; use crate::event_parse::{EventKind, EventKindVariation};
pub(crate) fn is_non_stripped_room_event(kind: EventKind, var: EventKindVariation) -> bool { pub(crate) fn is_non_stripped_room_event(kind: EventKind, var: EventKindVariation) -> bool {
matches!(kind, EventKind::Message | EventKind::State) matches!(kind, EventKind::MessageLike | EventKind::State)
&& matches!( && matches!(
var, var,
EventKindVariation::Full EventKindVariation::Full
@ -24,12 +24,12 @@ pub(crate) type EventKindFn = fn(EventKind, EventKindVariation) -> bool;
pub(crate) const EVENT_FIELDS: &[(&str, EventKindFn)] = &[ pub(crate) const EVENT_FIELDS: &[(&str, EventKindFn)] = &[
("origin_server_ts", is_non_stripped_room_event), ("origin_server_ts", is_non_stripped_room_event),
("room_id", |kind, var| { ("room_id", |kind, var| {
matches!(kind, EventKind::Message | EventKind::State | EventKind::Ephemeral) matches!(kind, EventKind::MessageLike | EventKind::State | EventKind::Ephemeral)
&& matches!(var, EventKindVariation::Full | EventKindVariation::Redacted) && matches!(var, EventKindVariation::Full | EventKindVariation::Redacted)
}), }),
("event_id", is_non_stripped_room_event), ("event_id", is_non_stripped_room_event),
("sender", |kind, var| { ("sender", |kind, var| {
matches!(kind, EventKind::Message | EventKind::State | EventKind::ToDevice) matches!(kind, EventKind::MessageLike | EventKind::State | EventKind::ToDevice)
&& var != EventKindVariation::Initial && var != EventKindVariation::Initial
}), }),
("state_key", |kind, _| matches!(kind, EventKind::State)), ("state_key", |kind, _| matches!(kind, EventKind::State)),

View File

@ -1,5 +1,9 @@
# [unreleased] # [unreleased]
Breaking changes:
* Rename `MessageEvent` and the associated types and traits to `MessageLikeEvent`
# 0.26.0 # 0.26.0
Breaking changes: Breaking changes:

View File

@ -4,7 +4,7 @@ use serde_json::value::RawValue as RawJsonValue;
use crate::{ use crate::{
EphemeralRoomEventContent, EventContent, GlobalAccountDataEventContent, HasDeserializeFields, EphemeralRoomEventContent, EventContent, GlobalAccountDataEventContent, HasDeserializeFields,
MessageEventContent, RedactContent, RedactedEventContent, RedactedMessageEventContent, MessageLikeEventContent, RedactContent, RedactedEventContent, RedactedMessageLikeEventContent,
RedactedStateEventContent, RoomAccountDataEventContent, StateEventContent, RedactedStateEventContent, RoomAccountDataEventContent, StateEventContent,
ToDeviceEventContent, ToDeviceEventContent,
}; };
@ -54,7 +54,7 @@ impl GlobalAccountDataEventContent for CustomEventContent {}
impl RoomAccountDataEventContent for CustomEventContent {} impl RoomAccountDataEventContent for CustomEventContent {}
impl ToDeviceEventContent for CustomEventContent {} impl ToDeviceEventContent for CustomEventContent {}
impl EphemeralRoomEventContent for CustomEventContent {} impl EphemeralRoomEventContent for CustomEventContent {}
impl MessageEventContent for CustomEventContent {} impl MessageLikeEventContent for CustomEventContent {}
impl StateEventContent for CustomEventContent {} impl StateEventContent for CustomEventContent {}
impl RedactedMessageEventContent for CustomEventContent {} impl RedactedMessageLikeEventContent for CustomEventContent {}
impl RedactedStateEventContent for CustomEventContent {} impl RedactedStateEventContent for CustomEventContent {}

View File

@ -13,7 +13,7 @@ use super::SessionDescription;
/// This event is sent by the callee when they wish to answer the call. /// This event is sent by the callee when they wish to answer the call.
#[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.call.answer", kind = Message)] #[ruma_event(type = "m.call.answer", kind = MessageLike)]
pub struct CallAnswerEventContent { pub struct CallAnswerEventContent {
/// The VoIP session description object. /// The VoIP session description object.
/// ///

View File

@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
/// purpose is to give the other party additional ICE candidates to try using to communicate. /// purpose is to give the other party additional ICE candidates to try using to communicate.
#[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.call.candidates", kind = Message)] #[ruma_event(type = "m.call.candidates", kind = MessageLike)]
pub struct CallCandidatesEventContent { pub struct CallCandidatesEventContent {
/// The ID of the call this event relates to. /// The ID of the call this event relates to.
pub call_id: String, pub call_id: String,

View File

@ -15,7 +15,7 @@ use crate::PrivOwnedStr;
/// call has has been established or before to abort the call. /// call has has been established or before to abort the call.
#[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.call.hangup", kind = Message)] #[ruma_event(type = "m.call.hangup", kind = MessageLike)]
pub struct CallHangupEventContent { pub struct CallHangupEventContent {
/// The ID of the call this event relates to. /// The ID of the call this event relates to.
pub call_id: String, pub call_id: String,

View File

@ -13,7 +13,7 @@ use super::SessionDescription;
/// This event is sent by the caller when they wish to establish a call. /// This event is sent by the caller when they wish to establish a call.
#[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.call.invite", kind = Message)] #[ruma_event(type = "m.call.invite", kind = MessageLike)]
pub struct CallInviteEventContent { pub struct CallInviteEventContent {
/// A unique identifier for the call. /// A unique identifier for the call.
pub call_id: String, pub call_id: String,

View File

@ -31,8 +31,8 @@ event_enum! {
"m.typing", "m.typing",
} }
/// Any message event. /// Any message-like event.
enum Message { enum MessageLike {
"m.call.answer", "m.call.answer",
"m.call.invite", "m.call.invite",
"m.call.hangup", "m.call.hangup",
@ -111,9 +111,9 @@ macro_rules! room_ev_accessor {
#[doc = concat!("Returns this event's `", stringify!($field), "` field.")] #[doc = concat!("Returns this event's `", stringify!($field), "` field.")]
pub fn $field(&self) -> $ty { pub fn $field(&self) -> $ty {
match self { match self {
Self::Message(ev) => ev.$field(), Self::MessageLike(ev) => ev.$field(),
Self::State(ev) => ev.$field(), Self::State(ev) => ev.$field(),
Self::RedactedMessage(ev) => ev.$field(), Self::RedactedMessageLike(ev) => ev.$field(),
Self::RedactedState(ev) => ev.$field(), Self::RedactedState(ev) => ev.$field(),
} }
} }
@ -125,14 +125,14 @@ macro_rules! room_ev_accessor {
#[allow(clippy::large_enum_variant, clippy::exhaustive_enums)] #[allow(clippy::large_enum_variant, clippy::exhaustive_enums)]
#[derive(Clone, Debug, EventEnumFromEvent)] #[derive(Clone, Debug, EventEnumFromEvent)]
pub enum AnyRoomEvent { pub enum AnyRoomEvent {
/// Any message event. /// Any message-like event.
Message(AnyMessageEvent), MessageLike(AnyMessageLikeEvent),
/// Any state event. /// Any state event.
State(AnyStateEvent), State(AnyStateEvent),
/// Any message event that has been redacted. /// Any message-like event that has been redacted.
RedactedMessage(AnyRedactedMessageEvent), RedactedMessageLike(AnyRedactedMessageLikeEvent),
/// Any state event that has been redacted. /// Any state event that has been redacted.
RedactedState(AnyRedactedStateEvent), RedactedState(AnyRedactedStateEvent),
@ -151,14 +151,14 @@ impl AnyRoomEvent {
#[allow(clippy::large_enum_variant, clippy::exhaustive_enums)] #[allow(clippy::large_enum_variant, clippy::exhaustive_enums)]
#[derive(Clone, Debug, EventEnumFromEvent)] #[derive(Clone, Debug, EventEnumFromEvent)]
pub enum AnySyncRoomEvent { pub enum AnySyncRoomEvent {
/// Any sync message event. /// Any sync message-like event.
Message(AnySyncMessageEvent), MessageLike(AnySyncMessageLikeEvent),
/// Any sync state event. /// Any sync state event.
State(AnySyncStateEvent), State(AnySyncStateEvent),
/// Any sync message event that has been redacted. /// Any sync message-like event that has been redacted.
RedactedMessage(AnyRedactedSyncMessageEvent), RedactedMessageLike(AnyRedactedSyncMessageLikeEvent),
/// Any sync state event that has been redacted. /// Any sync state event that has been redacted.
RedactedState(AnyRedactedSyncStateEvent), RedactedState(AnyRedactedSyncStateEvent),
@ -172,9 +172,11 @@ impl AnySyncRoomEvent {
/// Converts `self` to an `AnyRoomEvent` by adding the given a room ID. /// Converts `self` to an `AnyRoomEvent` by adding the given a room ID.
pub fn into_full_event(self, room_id: Box<RoomId>) -> AnyRoomEvent { pub fn into_full_event(self, room_id: Box<RoomId>) -> AnyRoomEvent {
match self { match self {
Self::Message(ev) => AnyRoomEvent::Message(ev.into_full_event(room_id)), Self::MessageLike(ev) => AnyRoomEvent::MessageLike(ev.into_full_event(room_id)),
Self::State(ev) => AnyRoomEvent::State(ev.into_full_event(room_id)), Self::State(ev) => AnyRoomEvent::State(ev.into_full_event(room_id)),
Self::RedactedMessage(ev) => AnyRoomEvent::RedactedMessage(ev.into_full_event(room_id)), Self::RedactedMessageLike(ev) => {
AnyRoomEvent::RedactedMessageLike(ev.into_full_event(room_id))
}
Self::RedactedState(ev) => AnyRoomEvent::RedactedState(ev.into_full_event(room_id)), Self::RedactedState(ev) => AnyRoomEvent::RedactedState(ev.into_full_event(room_id)),
} }
} }
@ -205,9 +207,9 @@ impl<'de> Deserialize<'de> for AnyRoomEvent {
} else { } else {
Ok(match unsigned { Ok(match unsigned {
Some(unsigned) if unsigned.redacted_because.is_some() => { Some(unsigned) if unsigned.redacted_because.is_some() => {
AnyRoomEvent::RedactedMessage(from_raw_json_value(&json)?) AnyRoomEvent::RedactedMessageLike(from_raw_json_value(&json)?)
} }
_ => AnyRoomEvent::Message(from_raw_json_value(&json)?), _ => AnyRoomEvent::MessageLike(from_raw_json_value(&json)?),
}) })
} }
} }
@ -231,9 +233,9 @@ impl<'de> Deserialize<'de> for AnySyncRoomEvent {
} else { } else {
Ok(match unsigned { Ok(match unsigned {
Some(unsigned) if unsigned.redacted_because.is_some() => { Some(unsigned) if unsigned.redacted_because.is_some() => {
AnySyncRoomEvent::RedactedMessage(from_raw_json_value(&json)?) AnySyncRoomEvent::RedactedMessageLike(from_raw_json_value(&json)?)
} }
_ => AnySyncRoomEvent::Message(from_raw_json_value(&json)?), _ => AnySyncRoomEvent::MessageLike(from_raw_json_value(&json)?),
}) })
} }
} }
@ -243,8 +245,8 @@ impl<'de> Deserialize<'de> for AnySyncRoomEvent {
#[allow(clippy::large_enum_variant, clippy::exhaustive_enums)] #[allow(clippy::large_enum_variant, clippy::exhaustive_enums)]
#[derive(Clone, Debug, EventEnumFromEvent)] #[derive(Clone, Debug, EventEnumFromEvent)]
pub enum AnyRedactedRoomEvent { pub enum AnyRedactedRoomEvent {
/// Any message event that has been redacted. /// Any message-like event that has been redacted.
Message(AnyRedactedMessageEvent), MessageLike(AnyRedactedMessageLikeEvent),
/// Any state event that has been redacted. /// Any state event that has been redacted.
State(AnyRedactedStateEvent), State(AnyRedactedStateEvent),
@ -258,9 +260,9 @@ impl Redact for AnyRoomEvent {
/// Does nothing for events that are already redacted. /// Does nothing for events that are already redacted.
fn redact(self, redaction: SyncRoomRedactionEvent, version: &RoomVersionId) -> Self::Redacted { fn redact(self, redaction: SyncRoomRedactionEvent, version: &RoomVersionId) -> Self::Redacted {
match self { match self {
Self::Message(ev) => Self::Redacted::Message(ev.redact(redaction, version)), Self::MessageLike(ev) => Self::Redacted::MessageLike(ev.redact(redaction, version)),
Self::State(ev) => Self::Redacted::State(ev.redact(redaction, version)), Self::State(ev) => Self::Redacted::State(ev.redact(redaction, version)),
Self::RedactedMessage(ev) => Self::Redacted::Message(ev), Self::RedactedMessageLike(ev) => Self::Redacted::MessageLike(ev),
Self::RedactedState(ev) => Self::Redacted::State(ev), Self::RedactedState(ev) => Self::Redacted::State(ev),
} }
} }
@ -269,7 +271,7 @@ impl Redact for AnyRoomEvent {
impl From<AnyRedactedRoomEvent> for AnyRoomEvent { impl From<AnyRedactedRoomEvent> for AnyRoomEvent {
fn from(ev: AnyRedactedRoomEvent) -> Self { fn from(ev: AnyRedactedRoomEvent) -> Self {
match ev { match ev {
AnyRedactedRoomEvent::Message(ev) => Self::RedactedMessage(ev), AnyRedactedRoomEvent::MessageLike(ev) => Self::RedactedMessageLike(ev),
AnyRedactedRoomEvent::State(ev) => Self::RedactedState(ev), AnyRedactedRoomEvent::State(ev) => Self::RedactedState(ev),
} }
} }
@ -279,8 +281,8 @@ impl From<AnyRedactedRoomEvent> for AnyRoomEvent {
#[allow(clippy::large_enum_variant, clippy::exhaustive_enums)] #[allow(clippy::large_enum_variant, clippy::exhaustive_enums)]
#[derive(Clone, Debug, EventEnumFromEvent)] #[derive(Clone, Debug, EventEnumFromEvent)]
pub enum AnyRedactedSyncRoomEvent { pub enum AnyRedactedSyncRoomEvent {
/// Any sync message event that has been redacted. /// Any sync message-like event that has been redacted.
Message(AnyRedactedSyncMessageEvent), MessageLike(AnyRedactedSyncMessageLikeEvent),
/// Any sync state event that has been redacted. /// Any sync state event that has been redacted.
State(AnyRedactedSyncStateEvent), State(AnyRedactedSyncStateEvent),
@ -294,9 +296,9 @@ impl Redact for AnySyncRoomEvent {
/// Does nothing for events that are already redacted. /// Does nothing for events that are already redacted.
fn redact(self, redaction: SyncRoomRedactionEvent, version: &RoomVersionId) -> Self::Redacted { fn redact(self, redaction: SyncRoomRedactionEvent, version: &RoomVersionId) -> Self::Redacted {
match self { match self {
Self::Message(ev) => Self::Redacted::Message(ev.redact(redaction, version)), Self::MessageLike(ev) => Self::Redacted::MessageLike(ev.redact(redaction, version)),
Self::State(ev) => Self::Redacted::State(ev.redact(redaction, version)), Self::State(ev) => Self::Redacted::State(ev.redact(redaction, version)),
Self::RedactedMessage(ev) => Self::Redacted::Message(ev), Self::RedactedMessageLike(ev) => Self::Redacted::MessageLike(ev),
Self::RedactedState(ev) => Self::Redacted::State(ev), Self::RedactedState(ev) => Self::Redacted::State(ev),
} }
} }
@ -305,17 +307,17 @@ impl Redact for AnySyncRoomEvent {
impl From<AnyRedactedSyncRoomEvent> for AnySyncRoomEvent { impl From<AnyRedactedSyncRoomEvent> for AnySyncRoomEvent {
fn from(ev: AnyRedactedSyncRoomEvent) -> Self { fn from(ev: AnyRedactedSyncRoomEvent) -> Self {
match ev { match ev {
AnyRedactedSyncRoomEvent::Message(ev) => Self::RedactedMessage(ev), AnyRedactedSyncRoomEvent::MessageLike(ev) => Self::RedactedMessageLike(ev),
AnyRedactedSyncRoomEvent::State(ev) => Self::RedactedState(ev), AnyRedactedSyncRoomEvent::State(ev) => Self::RedactedState(ev),
} }
} }
} }
impl AnyMessageEventContent { impl AnyMessageLikeEventContent {
/// Get a copy of the event's `m.relates_to` field, if any. /// Get a copy of the event's `m.relates_to` field, if any.
/// ///
/// This is a helper function intended for encryption. There should not be a reason to access /// This is a helper function intended for encryption. There should not be a reason to access
/// `m.relates_to` without first destructuring an `AnyMessageEventContent` otherwise. /// `m.relates_to` without first destructuring an `AnyMessageLikeEventContent` otherwise.
pub fn relation(&self) -> Option<encrypted::Relation> { pub fn relation(&self) -> Option<encrypted::Relation> {
use crate::key::verification::{ use crate::key::verification::{
accept::KeyVerificationAcceptEventContent, cancel::KeyVerificationCancelEventContent, accept::KeyVerificationAcceptEventContent, cancel::KeyVerificationCancelEventContent,

View File

@ -6,8 +6,8 @@ use ruma_identifiers::{EventId, RoomId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{ use crate::{
EphemeralRoomEventContent, GlobalAccountDataEventContent, MessageEventContent, EphemeralRoomEventContent, GlobalAccountDataEventContent, MessageLikeEventContent,
RedactedMessageEventContent, RedactedStateEventContent, RedactedUnsigned, RedactedMessageLikeEventContent, RedactedStateEventContent, RedactedUnsigned,
RoomAccountDataEventContent, StateEventContent, ToDeviceEventContent, Unsigned, RoomAccountDataEventContent, StateEventContent, ToDeviceEventContent, Unsigned,
}; };
@ -42,12 +42,12 @@ pub struct SyncEphemeralRoomEvent<C: EphemeralRoomEventContent> {
pub content: C, pub content: C,
} }
/// A message event. /// A message-like event.
/// ///
/// `MessageEvent` implements the comparison traits using only the `event_id` field, a sorted list /// `MessageLikeEvent` implements the comparison traits using only the `event_id` field, a sorted
/// would be sorted lexicographically based on the event's `EventId`. /// list would be sorted lexicographically based on the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct MessageEvent<C: MessageEventContent> { pub struct MessageLikeEvent<C: MessageLikeEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
pub content: C, pub content: C,
@ -67,12 +67,12 @@ pub struct MessageEvent<C: MessageEventContent> {
pub unsigned: Unsigned, pub unsigned: Unsigned,
} }
/// A message event without a `room_id`. /// A message-like event without a `room_id`.
/// ///
/// `SyncMessageEvent` implements the comparison traits using only the `event_id` field, a sorted /// `SyncMessageLikeEvent` implements the comparison traits using only the `event_id` field, a
/// list would be sorted lexicographically based on the event's `EventId`. /// sorted list would be sorted lexicographically based on the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct SyncMessageEvent<C: MessageEventContent> { pub struct SyncMessageLikeEvent<C: MessageLikeEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
pub content: C, pub content: C,
@ -89,12 +89,12 @@ pub struct SyncMessageEvent<C: MessageEventContent> {
pub unsigned: Unsigned, pub unsigned: Unsigned,
} }
/// A redacted message event. /// A redacted message-like event.
/// ///
/// `RedactedMessageEvent` implements the comparison traits using only the `event_id` field, a /// `RedactedMessageLikeEvent` implements the comparison traits using only the `event_id` field, a
/// sorted list would be sorted lexicographically based on the event's `EventId`. /// sorted list would be sorted lexicographically based on the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct RedactedMessageEvent<C: RedactedMessageEventContent> { pub struct RedactedMessageLikeEvent<C: RedactedMessageLikeEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
pub content: C, pub content: C,
@ -114,12 +114,12 @@ pub struct RedactedMessageEvent<C: RedactedMessageEventContent> {
pub unsigned: RedactedUnsigned, pub unsigned: RedactedUnsigned,
} }
/// A redacted message event without a `room_id`. /// A redacted message-like event without a `room_id`.
/// ///
/// `RedactedSyncMessageEvent` implements the comparison traits using only the `event_id` field, a /// `RedactedSyncMessageLikeEvent` implements the comparison traits using only the `event_id` field,
/// sorted list would be sorted lexicographically based on the event's `EventId`. /// a sorted list would be sorted lexicographically based on the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct RedactedSyncMessageEvent<C: RedactedMessageEventContent> { pub struct RedactedSyncMessageLikeEvent<C: RedactedMessageLikeEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
pub content: C, pub content: C,
@ -304,7 +304,7 @@ pub struct ToDeviceEvent<C: ToDeviceEventContent> {
/// The decrypted payload of an `m.olm.v1.curve25519-aes-sha2` event. /// The decrypted payload of an `m.olm.v1.curve25519-aes-sha2` event.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct DecryptedOlmV1Event<C: MessageEventContent> { pub struct DecryptedOlmV1Event<C: MessageLikeEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
pub content: C, pub content: C,
@ -330,7 +330,7 @@ pub struct OlmV1Keys {
/// The decrypted payload of an `m.megolm.v1.aes-sha2` event. /// The decrypted payload of an `m.megolm.v1.aes-sha2` event.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct DecryptedMegolmV1Event<C: MessageEventContent> { pub struct DecryptedMegolmV1Event<C: MessageLikeEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
pub content: C, pub content: C,

View File

@ -44,7 +44,7 @@ impl ToDeviceKeyVerificationAcceptEventContent {
/// ///
/// Accepts a previously sent `m.key.verification.start` message. /// Accepts a previously sent `m.key.verification.start` message.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[ruma_event(type = "m.key.verification.accept", kind = Message)] #[ruma_event(type = "m.key.verification.accept", kind = MessageLike)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct KeyVerificationAcceptEventContent { pub struct KeyVerificationAcceptEventContent {
/// The method specific content. /// The method specific content.

View File

@ -42,7 +42,7 @@ impl ToDeviceKeyVerificationCancelEventContent {
/// Cancels a key verification process/request. /// Cancels a key verification process/request.
#[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.key.verification.cancel", kind = Message)] #[ruma_event(type = "m.key.verification.cancel", kind = MessageLike)]
pub struct KeyVerificationCancelEventContent { pub struct KeyVerificationCancelEventContent {
/// A human readable description of the `code`. /// A human readable description of the `code`.
/// ///

View File

@ -33,7 +33,7 @@ impl ToDeviceKeyVerificationDoneEventContent {
/// Event signaling that the interactive key verification has successfully concluded. /// Event signaling that the interactive key verification has successfully concluded.
#[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.key.verification.done", kind = Message)] #[ruma_event(type = "m.key.verification.done", kind = MessageLike)]
pub struct KeyVerificationDoneEventContent { pub struct KeyVerificationDoneEventContent {
/// Relation signaling which verification request this event is responding to. /// Relation signaling which verification request this event is responding to.
#[serde(rename = "m.relates_to")] #[serde(rename = "m.relates_to")]

View File

@ -38,7 +38,7 @@ impl ToDeviceKeyVerificationKeyEventContent {
/// Sends the ephemeral public key for a device to the partner device. /// Sends the ephemeral public key for a device to the partner device.
#[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.key.verification.key", kind = Message)] #[ruma_event(type = "m.key.verification.key", kind = MessageLike)]
pub struct KeyVerificationKeyEventContent { pub struct KeyVerificationKeyEventContent {
/// The device's ephemeral public key, encoded as unpadded base64. /// The device's ephemeral public key, encoded as unpadded base64.
pub key: Base64, pub key: Base64,

View File

@ -50,7 +50,7 @@ impl ToDeviceKeyVerificationMacEventContent {
/// Sends the MAC of a device's key to the partner device. /// Sends the MAC of a device's key to the partner device.
#[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.key.verification.mac", kind = Message)] #[ruma_event(type = "m.key.verification.mac", kind = MessageLike)]
pub struct KeyVerificationMacEventContent { pub struct KeyVerificationMacEventContent {
/// A map of the key ID to the MAC of the key, using the algorithm in the verification process. /// A map of the key ID to the MAC of the key, using the algorithm in the verification process.
/// ///

View File

@ -46,7 +46,7 @@ impl ToDeviceKeyVerificationReadyEventContent {
/// Response to a previously sent `m.key.verification.request` message. /// Response to a previously sent `m.key.verification.request` message.
#[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.key.verification.ready", kind = Message)] #[ruma_event(type = "m.key.verification.ready", kind = MessageLike)]
pub struct KeyVerificationReadyEventContent { pub struct KeyVerificationReadyEventContent {
/// The device ID which is initiating the request. /// The device ID which is initiating the request.
pub from_device: Box<DeviceId>, pub from_device: Box<DeviceId>,

View File

@ -54,7 +54,7 @@ impl ToDeviceKeyVerificationStartEventContent {
/// Begins an SAS key verification process. /// Begins an SAS key verification process.
#[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.key.verification.start", kind = Message)] #[ruma_event(type = "m.key.verification.start", kind = MessageLike)]
pub struct KeyVerificationStartEventContent { pub struct KeyVerificationStartEventContent {
/// The device ID which is initiating the process. /// The device ID which is initiating the process.
pub from_device: Box<DeviceId>, pub from_device: Box<DeviceId>,

View File

@ -25,7 +25,7 @@
//! ruma-events includes Rust types for every one of the event types in the Matrix specification. //! ruma-events includes Rust types for every one of the event types in the Matrix specification.
//! To better organize the crate, these types live in separate modules with a hierarchy that //! To better organize the crate, these types live in separate modules with a hierarchy that
//! matches the reverse domain name notation of the event type. //! matches the reverse domain name notation of the event type.
//! For example, the `m.room.message` event lives at `ruma_events::room::message::MessageEvent`. //! For example, the `m.room.message` event lives at `ruma_events::room::message::MessageLikeEvent`.
//! Each type's module also contains a Rust type for that event type's `content` field, and any //! Each type's module also contains a Rust type for that event type's `content` field, and any
//! other supporting types required by the event's other fields. //! other supporting types required by the event's other fields.
//! //!
@ -49,10 +49,10 @@
//! `ruma::api::client::state::send_state_event`'s `Request`. //! `ruma::api::client::state::send_state_event`'s `Request`.
//! //!
//! As a more advanced example we create a reaction message event. For this event we will use a //! As a more advanced example we create a reaction message event. For this event we will use a
//! `SyncMessageEvent` struct but any `MessageEvent` struct would work. //! `SyncMessageLikeEvent` struct but any `MessageLikeEvent` struct would work.
//! //!
//! ```rust //! ```rust
//! use ruma_events::{macros::EventContent, SyncMessageEvent}; //! use ruma_events::{macros::EventContent, SyncMessageLikeEvent};
//! use ruma_identifiers::EventId; //! use ruma_identifiers::EventId;
//! use serde::{Deserialize, Serialize}; //! use serde::{Deserialize, Serialize};
//! //!
@ -75,7 +75,7 @@
//! //!
//! /// The payload for our reaction event. //! /// The payload for our reaction event.
//! #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] //! #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
//! #[ruma_event(type = "m.reaction", kind = Message)] //! #[ruma_event(type = "m.reaction", kind = MessageLike)]
//! pub struct ReactionEventContent { //! pub struct ReactionEventContent {
//! #[serde(rename = "m.relates_to")] //! #[serde(rename = "m.relates_to")]
//! pub relates_to: RelatesTo, //! pub relates_to: RelatesTo,
@ -101,8 +101,8 @@
//! // The downside of this event is we cannot use it with event enums, //! // The downside of this event is we cannot use it with event enums,
//! // but could be deserialized from a `Raw<_>` that has failed to deserialize. //! // but could be deserialized from a `Raw<_>` that has failed to deserialize.
//! matches::assert_matches!( //! matches::assert_matches!(
//! serde_json::from_value::<SyncMessageEvent<ReactionEventContent>>(json), //! serde_json::from_value::<SyncMessageLikeEvent<ReactionEventContent>>(json),
//! Ok(SyncMessageEvent { //! Ok(SyncMessageLikeEvent {
//! content: ReactionEventContent { //! content: ReactionEventContent {
//! relates_to: RelatesTo::Annotation { key, .. }, //! relates_to: RelatesTo::Annotation { key, .. },
//! }, //! },
@ -267,8 +267,8 @@ pub trait RoomAccountDataEventContent: EventContent {}
/// Marker trait for the content of a to device event. /// Marker trait for the content of a to device event.
pub trait ToDeviceEventContent: EventContent {} pub trait ToDeviceEventContent: EventContent {}
/// Marker trait for the content of a message event. /// Marker trait for the content of a message-like event.
pub trait MessageEventContent: EventContent {} pub trait MessageLikeEventContent: EventContent {}
/// Marker trait for the content of a state event. /// Marker trait for the content of a state event.
pub trait StateEventContent: EventContent {} pub trait StateEventContent: EventContent {}
@ -277,7 +277,7 @@ pub trait StateEventContent: EventContent {}
/// ///
/// This trait's associated functions and methods should not be used to build /// This trait's associated functions and methods should not be used to build
/// redacted events, prefer the `redact` method on `AnyStateEvent` and /// redacted events, prefer the `redact` method on `AnyStateEvent` and
/// `AnyMessageEvent` and their "sync" and "stripped" counterparts. The /// `AnyMessageLikeEvent` and their "sync" and "stripped" counterparts. The
/// `RedactedEventContent` trait is an implementation detail, ruma makes no /// `RedactedEventContent` trait is an implementation detail, ruma makes no
/// API guarantees. /// API guarantees.
pub trait RedactedEventContent: EventContent { pub trait RedactedEventContent: EventContent {
@ -298,8 +298,8 @@ pub trait RedactedEventContent: EventContent {
fn has_deserialize_fields() -> HasDeserializeFields; fn has_deserialize_fields() -> HasDeserializeFields;
} }
/// Marker trait for the content of a redacted message event. /// Marker trait for the content of a redacted message-like event.
pub trait RedactedMessageEventContent: RedactedEventContent {} pub trait RedactedMessageLikeEventContent: RedactedEventContent {}
/// Marker trait for the content of a redacted state event. /// Marker trait for the content of a redacted state event.
pub trait RedactedStateEventContent: RedactedEventContent {} pub trait RedactedStateEventContent: RedactedEventContent {}
@ -333,11 +333,12 @@ pub enum EventKind {
/// Ephemeral room event kind. /// Ephemeral room event kind.
EphemeralRoomData, EphemeralRoomData,
/// Message event kind. /// Message-like event kind.
/// ///
/// Since redacted / non-redacted message events are used in the same places bu have different /// Since redacted / non-redacted message-like events are used in the same places bu have
/// sets of fields, these two variations are treated as two closely-related event kinds. /// different sets of fields, these two variations are treated as two closely-related event
Message { /// kinds.
MessageLike {
/// Redacted variation? /// Redacted variation?
redacted: bool, redacted: bool,
}, },

View File

@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
/// A reaction to another event. /// A reaction to another event.
#[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.reaction", kind = Message)] #[ruma_event(type = "m.reaction", kind = MessageLike)]
pub struct ReactionEventContent { pub struct ReactionEventContent {
/// Information about the related event. /// Information about the related event.
#[serde(rename = "m.relates_to")] #[serde(rename = "m.relates_to")]

View File

@ -16,7 +16,7 @@ mod relation_serde;
/// The content of an `m.room.encrypted` event. /// The content of an `m.room.encrypted` event.
#[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.room.encrypted", kind = Message, kind = ToDevice)] #[ruma_event(type = "m.room.encrypted", kind = MessageLike, kind = ToDevice)]
pub struct RoomEncryptedEventContent { pub struct RoomEncryptedEventContent {
/// Algorithm-specific fields. /// Algorithm-specific fields.
#[serde(flatten)] #[serde(flatten)]

View File

@ -28,7 +28,7 @@ pub use reply::ReplyBaseEvent;
/// Messages are not limited to be text. /// Messages are not limited to be text.
#[derive(Clone, Debug, Serialize, EventContent)] #[derive(Clone, Debug, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.room.message", kind = Message)] #[ruma_event(type = "m.room.message", kind = MessageLike)]
pub struct RoomMessageEventContent { pub struct RoomMessageEventContent {
/// A key which identifies the type of message being sent. /// A key which identifies the type of message being sent.
/// ///
@ -103,7 +103,7 @@ impl RoomMessageEventContent {
/// Different from `text_reply_plain`, this constructor requires specifically a /// Different from `text_reply_plain`, this constructor requires specifically a
/// [`RoomMessageEvent`] since it creates a permalink to the previous message, for which the /// [`RoomMessageEvent`] since it creates a permalink to the previous message, for which the
/// room ID is required. If you want to reply to a [`SyncRoomMessageEvent`], you have to convert /// room ID is required. If you want to reply to a [`SyncRoomMessageEvent`], you have to convert
/// it first by calling [`.into_full_event()`][crate::SyncMessageEvent::into_full_event]. /// it first by calling [`.into_full_event()`][crate::SyncMessageLikeEvent::into_full_event].
pub fn text_reply_html( pub fn text_reply_html(
reply: impl fmt::Display, reply: impl fmt::Display,
html_reply: impl fmt::Display, html_reply: impl fmt::Display,
@ -144,7 +144,7 @@ impl RoomMessageEventContent {
/// Different from `notice_reply_plain`, this constructor requires specifically a /// Different from `notice_reply_plain`, this constructor requires specifically a
/// [`RoomMessageEvent`] since it creates a permalink to the previous message, for which the /// [`RoomMessageEvent`] since it creates a permalink to the previous message, for which the
/// room ID is required. If you want to reply to a [`SyncRoomMessageEvent`], you have to convert /// room ID is required. If you want to reply to a [`SyncRoomMessageEvent`], you have to convert
/// it first by calling [`.into_full_event()`][crate::SyncMessageEvent::into_full_event]. /// it first by calling [`.into_full_event()`][crate::SyncMessageLikeEvent::into_full_event].
pub fn notice_reply_html( pub fn notice_reply_html(
reply: impl fmt::Display, reply: impl fmt::Display,
html_reply: impl fmt::Display, html_reply: impl fmt::Display,

View File

@ -17,7 +17,7 @@ use crate::PrivOwnedStr;
/// not recognize this event. /// not recognize this event.
#[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.room.message.feedback", kind = Message)] #[ruma_event(type = "m.room.message.feedback", kind = MessageLike)]
pub struct RoomMessageFeedbackEventContent { pub struct RoomMessageFeedbackEventContent {
/// The event that this feedback is related to. /// The event that this feedback is related to.
pub target_event_id: Box<EventId>, pub target_event_id: Box<EventId>,

View File

@ -7,8 +7,9 @@ use super::{
/// An event that can be replied to. /// An event that can be replied to.
/// ///
/// This trait only exists to allow the plain-text `reply` constructors on `MessageEventContent` to /// This trait only exists to allow the plain-text `reply` constructors on `MessageLikeEventContent`
/// use either a [`RoomMessageEvent`] or a [`SyncRoomMessageEvent`] as the event being replied to. /// to use either a [`RoomMessageEvent`] or a [`SyncRoomMessageEvent`] as the event being replied
/// to.
pub trait ReplyBaseEvent { pub trait ReplyBaseEvent {
#[doc(hidden)] #[doc(hidden)]
fn event_id(&self) -> &EventId; fn event_id(&self) -> &EventId;

View File

@ -151,7 +151,7 @@ pub struct RedactedSyncRoomRedactionEvent {
/// A redaction of an event. /// A redaction of an event.
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)] #[derive(Clone, Debug, Default, 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.room.redaction", kind = Message)] #[ruma_event(type = "m.room.redaction", kind = MessageLike)]
pub struct RoomRedactionEventContent { pub struct RoomRedactionEventContent {
/// The reason for the redaction, if any. /// The reason for the redaction, if any.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]

View File

@ -13,7 +13,7 @@ use crate::room::ImageInfo;
/// A sticker message. /// A sticker message.
#[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.sticker", kind = Message)] #[ruma_event(type = "m.sticker", kind = MessageLike)]
pub struct StickerEventContent { pub struct StickerEventContent {
/// A textual representation or associated description of the sticker image. /// A textual representation or associated description of the sticker image.
/// ///

View File

@ -11,10 +11,11 @@ use ruma_events::{
message::{MessageType, RoomMessageEventContent, TextMessageEventContent}, message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
power_levels::RoomPowerLevelsEventContent, power_levels::RoomPowerLevelsEventContent,
}, },
AnyEphemeralRoomEvent, AnyMessageEvent, AnyRoomEvent, AnyStateEvent, AnyStateEventContent, AnyEphemeralRoomEvent, AnyMessageLikeEvent, AnyRoomEvent, AnyStateEvent, AnyStateEventContent,
AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent, EphemeralRoomEventType, EventType, AnySyncMessageLikeEvent, AnySyncRoomEvent, AnySyncStateEvent, EphemeralRoomEventType,
GlobalAccountDataEventType, MessageEvent, MessageEventType, RoomAccountDataEventType, EventType, GlobalAccountDataEventType, MessageLikeEvent, MessageLikeEventType,
StateEvent, StateEventType, SyncMessageEvent, SyncStateEvent, ToDeviceEventType, Unsigned, RoomAccountDataEventType, StateEvent, StateEventType, SyncMessageLikeEvent, SyncStateEvent,
ToDeviceEventType, Unsigned,
}; };
fn message_event() -> JsonValue { fn message_event() -> JsonValue {
@ -139,8 +140,8 @@ fn message_event_sync_deserialization() {
assert_matches!( assert_matches!(
from_json_value::<AnySyncRoomEvent>(json_data), from_json_value::<AnySyncRoomEvent>(json_data),
Ok(AnySyncRoomEvent::Message( Ok(AnySyncRoomEvent::MessageLike(
AnySyncMessageEvent::RoomMessage(SyncMessageEvent { AnySyncMessageLikeEvent::RoomMessage(SyncMessageLikeEvent {
content: RoomMessageEventContent { content: RoomMessageEventContent {
msgtype: MessageType::Text(TextMessageEventContent { msgtype: MessageType::Text(TextMessageEventContent {
body, body,
@ -181,8 +182,8 @@ fn message_room_event_deserialization() {
assert_matches!( assert_matches!(
from_json_value::<AnyRoomEvent>(json_data), from_json_value::<AnyRoomEvent>(json_data),
Ok(AnyRoomEvent::Message( Ok(AnyRoomEvent::MessageLike(
AnyMessageEvent::RoomMessage(MessageEvent { AnyMessageLikeEvent::RoomMessage(MessageLikeEvent {
content: RoomMessageEventContent { content: RoomMessageEventContent {
msgtype: MessageType::Text(TextMessageEventContent { msgtype: MessageType::Text(TextMessageEventContent {
body, body,
@ -200,7 +201,7 @@ fn message_room_event_deserialization() {
#[test] #[test]
fn message_event_serialization() { fn message_event_serialization() {
let event = MessageEvent { let event = MessageLikeEvent {
content: RoomMessageEventContent::text_plain("test"), content: RoomMessageEventContent::text_plain("test"),
event_id: event_id!("$1234:example.com").to_owned(), event_id: event_id!("$1234:example.com").to_owned(),
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(0)), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(0)),
@ -240,8 +241,8 @@ fn message_event_deserialization() {
assert_matches!( assert_matches!(
from_json_value::<AnyRoomEvent>(json_data), from_json_value::<AnyRoomEvent>(json_data),
Ok(AnyRoomEvent::Message( Ok(AnyRoomEvent::MessageLike(
AnyMessageEvent::RoomMessage(MessageEvent { AnyMessageLikeEvent::RoomMessage(MessageLikeEvent {
content: RoomMessageEventContent { content: RoomMessageEventContent {
msgtype: MessageType::Text(TextMessageEventContent { msgtype: MessageType::Text(TextMessageEventContent {
body, body,
@ -323,7 +324,7 @@ fn ephemeral_event_deserialization() {
#[test] #[test]
fn serialize_and_deserialize_from_display_form() { fn serialize_and_deserialize_from_display_form() {
serde_json_eq(EventType::CallAnswer, json!("m.call.answer")); serde_json_eq(EventType::CallAnswer, json!("m.call.answer"));
serde_json_eq(MessageEventType::CallAnswer, json!("m.call.answer")); serde_json_eq(MessageLikeEventType::CallAnswer, json!("m.call.answer"));
serde_json_eq(EventType::CallCandidates, json!("m.call.candidates")); serde_json_eq(EventType::CallCandidates, json!("m.call.candidates"));
serde_json_eq(EventType::CallHangup, json!("m.call.hangup")); serde_json_eq(EventType::CallHangup, json!("m.call.hangup"));
serde_json_eq(EventType::CallInvite, json!("m.call.invite")); serde_json_eq(EventType::CallInvite, json!("m.call.invite"));

View File

@ -6,7 +6,7 @@ use serde_json::{from_value as from_json_value, json};
use ruma_events::{ use ruma_events::{
call::{answer::CallAnswerEventContent, SessionDescription, SessionDescriptionType}, call::{answer::CallAnswerEventContent, SessionDescription, SessionDescriptionType},
AnyMessageEvent, MessageEvent, AnyMessageLikeEvent, MessageLikeEvent,
}; };
#[test] #[test]
@ -36,9 +36,9 @@ fn deserialize_message_event() {
}); });
assert_matches!( assert_matches!(
from_json_value::<AnyMessageEvent>(json_data) from_json_value::<AnyMessageLikeEvent>(json_data)
.unwrap(), .unwrap(),
AnyMessageEvent::CallAnswer(MessageEvent { AnyMessageLikeEvent::CallAnswer(MessageLikeEvent {
content: CallAnswerEventContent { content: CallAnswerEventContent {
answer: SessionDescription { answer: SessionDescription {
session_type: SessionDescriptionType::Answer, session_type: SessionDescriptionType::Answer,

View File

@ -6,7 +6,8 @@ use ruma_events::{
call::{answer::CallAnswerEventContent, SessionDescription, SessionDescriptionType}, call::{answer::CallAnswerEventContent, SessionDescription, SessionDescriptionType},
room::{ImageInfo, ThumbnailInfo}, room::{ImageInfo, ThumbnailInfo},
sticker::StickerEventContent, sticker::StickerEventContent,
AnyMessageEvent, AnyMessageEventContent, AnySyncMessageEvent, MessageEvent, RawExt, Unsigned, AnyMessageLikeEvent, AnyMessageLikeEventContent, AnySyncMessageLikeEvent, MessageLikeEvent,
RawExt, Unsigned,
}; };
use ruma_identifiers::{event_id, mxc_uri, room_id, user_id}; use ruma_identifiers::{event_id, mxc_uri, room_id, user_id};
use ruma_serde::Raw; use ruma_serde::Raw;
@ -14,7 +15,7 @@ use serde_json::{from_value as from_json_value, json, to_value as to_json_value}
#[test] #[test]
fn message_serialize_sticker() { fn message_serialize_sticker() {
let aliases_event = MessageEvent { let aliases_event = MessageLikeEvent {
content: StickerEventContent::new( content: StickerEventContent::new(
"Hello".into(), "Hello".into(),
assign!(ImageInfo::new(), { assign!(ImageInfo::new(), {
@ -80,11 +81,11 @@ fn deserialize_message_call_answer_content() {
}); });
assert_matches!( assert_matches!(
from_json_value::<Raw<AnyMessageEventContent>>(json_data) from_json_value::<Raw<AnyMessageLikeEventContent>>(json_data)
.unwrap() .unwrap()
.deserialize_content("m.call.answer") .deserialize_content("m.call.answer")
.unwrap(), .unwrap(),
AnyMessageEventContent::CallAnswer(CallAnswerEventContent { AnyMessageLikeEventContent::CallAnswer(CallAnswerEventContent {
answer: SessionDescription { answer: SessionDescription {
session_type: SessionDescriptionType::Answer, session_type: SessionDescriptionType::Answer,
sdp, sdp,
@ -116,8 +117,8 @@ fn deserialize_message_call_answer() {
}); });
assert_matches!( assert_matches!(
from_json_value::<AnyMessageEvent>(json_data).unwrap(), from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
AnyMessageEvent::CallAnswer(MessageEvent { AnyMessageLikeEvent::CallAnswer(MessageLikeEvent {
content: CallAnswerEventContent { content: CallAnswerEventContent {
answer: SessionDescription { answer: SessionDescription {
session_type: SessionDescriptionType::Answer, session_type: SessionDescriptionType::Answer,
@ -170,8 +171,8 @@ fn deserialize_message_sticker() {
}); });
assert_matches!( assert_matches!(
from_json_value::<AnyMessageEvent>(json_data).unwrap(), from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
AnyMessageEvent::Sticker(MessageEvent { AnyMessageLikeEvent::Sticker(MessageLikeEvent {
content: StickerEventContent { content: StickerEventContent {
body, body,
info: ImageInfo { info: ImageInfo {
@ -240,11 +241,11 @@ fn deserialize_message_then_convert_to_full() {
"type": "m.call.answer" "type": "m.call.answer"
}); });
let sync_ev: AnySyncMessageEvent = from_json_value(json_data).unwrap(); let sync_ev: AnySyncMessageLikeEvent = from_json_value(json_data).unwrap();
assert_matches!( assert_matches!(
sync_ev.into_full_event(rid.to_owned()), sync_ev.into_full_event(rid.to_owned()),
AnyMessageEvent::CallAnswer(MessageEvent { AnyMessageLikeEvent::CallAnswer(MessageLikeEvent {
content: CallAnswerEventContent { content: CallAnswerEventContent {
answer: SessionDescription { answer: SessionDescription {
session_type: SessionDescriptionType::Answer, session_type: SessionDescriptionType::Answer,

View File

@ -8,10 +8,10 @@ use ruma_events::{
message::{RedactedRoomMessageEventContent, RoomMessageEventContent}, message::{RedactedRoomMessageEventContent, RoomMessageEventContent},
redaction::{RoomRedactionEventContent, SyncRoomRedactionEvent}, redaction::{RoomRedactionEventContent, SyncRoomRedactionEvent},
}, },
AnyMessageEvent, AnyRedactedMessageEvent, AnyRedactedSyncMessageEvent, AnyMessageLikeEvent, AnyRedactedMessageLikeEvent, AnyRedactedSyncMessageLikeEvent,
AnyRedactedSyncStateEvent, AnyRoomEvent, AnySyncRoomEvent, EventContent, Redact, RedactContent, AnyRedactedSyncStateEvent, AnyRoomEvent, AnySyncRoomEvent, EventContent, Redact, RedactContent,
RedactedMessageEvent, RedactedSyncMessageEvent, RedactedSyncStateEvent, RedactedUnsigned, RedactedMessageLikeEvent, RedactedSyncMessageLikeEvent, RedactedSyncStateEvent,
Unsigned, RedactedUnsigned, Unsigned,
}; };
use ruma_identifiers::{event_id, room_id, user_id, RoomVersionId}; use ruma_identifiers::{event_id, room_id, user_id, RoomVersionId};
use serde_json::{ use serde_json::{
@ -35,7 +35,7 @@ fn unsigned() -> RedactedUnsigned {
#[test] #[test]
fn redacted_message_event_serialize() { fn redacted_message_event_serialize() {
let redacted = RedactedSyncMessageEvent { let redacted = RedactedSyncMessageLikeEvent {
content: RedactedRoomMessageEventContent::new(), content: RedactedRoomMessageEventContent::new(),
event_id: event_id!("$h29iv0s8:example.com").to_owned(), event_id: event_id!("$h29iv0s8:example.com").to_owned(),
origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)), origin_server_ts: MilliSecondsSinceUnixEpoch(uint!(1)),
@ -144,7 +144,7 @@ fn redacted_deserialize_any_room() {
assert_matches!( assert_matches!(
from_json_value::<AnyRoomEvent>(actual).unwrap(), from_json_value::<AnyRoomEvent>(actual).unwrap(),
AnyRoomEvent::RedactedMessage(AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent { AnyRoomEvent::RedactedMessageLike(AnyRedactedMessageLikeEvent::RoomMessage(RedactedMessageLikeEvent {
content: RedactedRoomMessageEventContent { .. }, content: RedactedRoomMessageEventContent { .. },
event_id, room_id, .. event_id, room_id, ..
})) if event_id == event_id!("$h29iv0s8:example.com") })) if event_id == event_id!("$h29iv0s8:example.com")
@ -179,8 +179,8 @@ fn redacted_deserialize_any_room_sync() {
assert_matches!( assert_matches!(
from_json_value::<AnySyncRoomEvent>(actual).unwrap(), from_json_value::<AnySyncRoomEvent>(actual).unwrap(),
AnySyncRoomEvent::RedactedMessage(AnyRedactedSyncMessageEvent::RoomMessage( AnySyncRoomEvent::RedactedMessageLike(AnyRedactedSyncMessageLikeEvent::RoomMessage(
RedactedSyncMessageEvent { RedactedSyncMessageLikeEvent {
content: RedactedRoomMessageEventContent { .. }, content: RedactedRoomMessageEventContent { .. },
event_id, event_id,
.. ..
@ -267,11 +267,11 @@ fn redact_method_properly_redacts() {
unsigned: Unsigned::default(), unsigned: Unsigned::default(),
}; };
let event: AnyMessageEvent = from_json_value(ev).unwrap(); let event: AnyMessageLikeEvent = from_json_value(ev).unwrap();
assert_matches!( assert_matches!(
event.redact(redaction, &RoomVersionId::V6), event.redact(redaction, &RoomVersionId::V6),
AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent { AnyRedactedMessageLikeEvent::RoomMessage(RedactedMessageLikeEvent {
content: RedactedRoomMessageEventContent { .. }, content: RedactedRoomMessageEventContent { .. },
event_id, event_id,
room_id, room_id,

View File

@ -3,7 +3,7 @@ use matches::assert_matches;
use ruma_common::MilliSecondsSinceUnixEpoch; use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{ use ruma_events::{
room::redaction::{RoomRedactionEvent, RoomRedactionEventContent}, room::redaction::{RoomRedactionEvent, RoomRedactionEventContent},
AnyMessageEvent, Unsigned, AnyMessageLikeEvent, Unsigned,
}; };
use ruma_identifiers::{event_id, room_id, user_id}; use ruma_identifiers::{event_id, room_id, user_id};
use serde_json::{ use serde_json::{
@ -47,8 +47,8 @@ fn deserialize_redaction() {
let json_data = redaction(); let json_data = redaction();
assert_matches!( assert_matches!(
from_json_value::<AnyMessageEvent>(json_data).unwrap(), from_json_value::<AnyMessageLikeEvent>(json_data).unwrap(),
AnyMessageEvent::RoomRedaction(RoomRedactionEvent { AnyMessageLikeEvent::RoomRedaction(RoomRedactionEvent {
content: RoomRedactionEventContent { reason: Some(reas), .. }, content: RoomRedactionEventContent { reason: Some(reas), .. },
redacts, redacts,
event_id, event_id,

View File

@ -1,4 +1,4 @@
error: valid event kinds are GlobalAccountData, RoomAccountData, EphemeralRoom, Message, State, ToDevice found `NotReal` error: valid event kinds are GlobalAccountData, RoomAccountData, EphemeralRoom, MessageLike, State, ToDevice found `NotReal`
--> $DIR/09-enum-invalid-kind.rs:4:10 --> $DIR/09-enum-invalid-kind.rs:4:10
| |
4 | enum NotReal { 4 | enum NotReal {

View File

@ -5,7 +5,7 @@ use ruma::{
api::client::{filter::FilterDefinition, sync::sync_events}, api::client::{filter::FilterDefinition, sync::sync_events},
events::{ events::{
room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent}, room::message::{MessageType, RoomMessageEventContent, TextMessageEventContent},
AnySyncMessageEvent, AnySyncRoomEvent, SyncMessageEvent, AnySyncMessageLikeEvent, AnySyncRoomEvent, SyncMessageLikeEvent,
}, },
presence::PresenceState, presence::PresenceState,
}; };
@ -42,8 +42,8 @@ async fn log_messages(
for (room_id, room) in res.rooms.join { for (room_id, room) in res.rooms.join {
for event in room.timeline.events.into_iter().flat_map(|r| r.deserialize()) { for event in room.timeline.events.into_iter().flat_map(|r| r.deserialize()) {
// Filter out the text messages // Filter out the text messages
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage( if let AnySyncRoomEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
SyncMessageEvent { SyncMessageLikeEvent {
content: content:
RoomMessageEventContent { RoomMessageEventContent {
msgtype: msgtype:

View File

@ -9,7 +9,7 @@ use ruma::{
assign, client, assign, client,
events::{ events::{
room::message::{MessageType, RoomMessageEventContent}, room::message::{MessageType, RoomMessageEventContent},
AnySyncMessageEvent, AnySyncRoomEvent, AnySyncMessageLikeEvent, AnySyncRoomEvent,
}, },
identifiers::TransactionId, identifiers::TransactionId,
presence::PresenceState, presence::PresenceState,
@ -147,7 +147,9 @@ async fn handle_message(
room_id: &RoomId, room_id: &RoomId,
bot_user_id: &UserId, bot_user_id: &UserId,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
if let Ok(AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(m))) = e.deserialize() { if let Ok(AnySyncRoomEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(m))) =
e.deserialize()
{
// workaround because Conduit does not implement filtering. // workaround because Conduit does not implement filtering.
if m.sender == bot_user_id { if m.sender == bot_user_id {
return Ok(()); return Ok(());