Add global and room account content traits and to device trait
This commit is contained in:
parent
8252a1a32c
commit
b6558c64a0
@ -292,10 +292,12 @@ fn generate_event_content_derives(
|
||||
.map(|kind| {
|
||||
Ok(match kind {
|
||||
EventKind::GlobalAccountData => quote! {
|
||||
// TODO: will this be it's own trait at some point?
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::GlobalAccountDataEventContent for #ident {}
|
||||
},
|
||||
EventKind::RoomAccountData => quote! {
|
||||
// TODO: will this be it's own trait at some point?
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::RoomAccountDataEventContent for #ident {}
|
||||
},
|
||||
EventKind::Ephemeral => quote! {
|
||||
#[automatically_derived]
|
||||
@ -314,10 +316,11 @@ fn generate_event_content_derives(
|
||||
impl #ruma_events::StateEventContent for #ident {}
|
||||
},
|
||||
EventKind::ToDevice => quote! {
|
||||
// TODO: will this be it's own trait at some point?
|
||||
#[automatically_derived]
|
||||
impl #ruma_events::ToDeviceEventContent for #ident {}
|
||||
},
|
||||
EventKind::Redaction => return Err(syn::Error::new(ident.span(), msg)),
|
||||
EventKind::Presence => return Err(syn::Error::new(ident.span(), msg)),
|
||||
EventKind::Redaction => return Err(syn::Error::new_spanned(ident, msg)),
|
||||
EventKind::Presence => return Err(syn::Error::new_spanned(ident, msg)),
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
|
@ -7,9 +7,10 @@ use serde::Serialize;
|
||||
use serde_json::{value::RawValue as RawJsonValue, Value as JsonValue};
|
||||
|
||||
use crate::{
|
||||
BasicEventContent, EphemeralRoomEventContent, EventContent, HasDeserializeFields,
|
||||
EphemeralRoomEventContent, EventContent, GlobalAccountDataEventContent, HasDeserializeFields,
|
||||
MessageEventContent, RedactedEventContent, RedactedMessageEventContent,
|
||||
RedactedStateEventContent, RoomEventContent, StateEventContent,
|
||||
RedactedStateEventContent, RoomAccountDataEventContent, RoomEventContent, StateEventContent,
|
||||
ToDeviceEventContent,
|
||||
};
|
||||
|
||||
/// A custom event's type and `content` JSON object.
|
||||
@ -46,7 +47,11 @@ impl EventContent for CustomEventContent {
|
||||
// they can be used for any event kind.
|
||||
impl RoomEventContent for CustomEventContent {}
|
||||
|
||||
impl BasicEventContent for CustomEventContent {}
|
||||
impl GlobalAccountDataEventContent for CustomEventContent {}
|
||||
|
||||
impl RoomAccountDataEventContent for CustomEventContent {}
|
||||
|
||||
impl ToDeviceEventContent for CustomEventContent {}
|
||||
|
||||
impl EphemeralRoomEventContent for CustomEventContent {}
|
||||
|
||||
|
@ -17,7 +17,7 @@ pub type DirectEvent = crate::GlobalAccountDataEvent<DirectEventContent>;
|
||||
/// A mapping of `UserId`s to a list of `RoomId`s which are considered *direct* for that
|
||||
/// particular user.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||
#[ruma_event(type = "m.direct")]
|
||||
#[ruma_event(type = "m.direct", kind = GlobalAccountData)]
|
||||
pub struct DirectEventContent(pub BTreeMap<UserId, Vec<RoomId>>);
|
||||
|
||||
impl Deref for DirectEventContent {
|
||||
|
@ -3,20 +3,21 @@ use ruma_events_macros::Event;
|
||||
use ruma_identifiers::{EventId, RoomId, UserId};
|
||||
|
||||
use crate::{
|
||||
EphemeralRoomEventContent, EventContent, MessageEventContent, RedactedMessageEventContent,
|
||||
RedactedStateEventContent, RedactedSyncUnsigned, RedactedUnsigned, StateEventContent, Unsigned,
|
||||
EphemeralRoomEventContent, EventContent, GlobalAccountDataEventContent, MessageEventContent,
|
||||
RedactedMessageEventContent, RedactedStateEventContent, RedactedSyncUnsigned, RedactedUnsigned,
|
||||
RoomAccountDataEventContent, StateEventContent, Unsigned,
|
||||
};
|
||||
|
||||
/// A global account data event.
|
||||
#[derive(Clone, Debug, Event)]
|
||||
pub struct GlobalAccountDataEvent<C: EventContent> {
|
||||
pub struct GlobalAccountDataEvent<C: GlobalAccountDataEventContent> {
|
||||
/// Data specific to the event type.
|
||||
pub content: C,
|
||||
}
|
||||
|
||||
/// A room account data event.
|
||||
#[derive(Clone, Debug, Event)]
|
||||
pub struct RoomAccountDataEvent<C: EventContent> {
|
||||
pub struct RoomAccountDataEvent<C: RoomAccountDataEventContent> {
|
||||
/// Data specific to the event type.
|
||||
pub content: C,
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ pub type FullyReadEvent = RoomAccountDataEvent<FullyReadEventContent>;
|
||||
|
||||
/// The payload for `FullyReadEvent`.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||
#[ruma_event(type = "m.fully_read")]
|
||||
#[ruma_event(type = "m.fully_read", kind = RoomAccountData)]
|
||||
pub struct FullyReadEventContent {
|
||||
/// The event the user's read marker is located at in the room.
|
||||
pub event_id: EventId,
|
||||
|
@ -12,7 +12,7 @@ pub type IgnoredUserListEvent = GlobalAccountDataEvent<IgnoredUserListEventConte
|
||||
/// The payload for `IgnoredUserListEvent`.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[ruma_event(type = "m.ignored_user_list")]
|
||||
#[ruma_event(type = "m.ignored_user_list", kind = GlobalAccountData)]
|
||||
pub struct IgnoredUserListEventContent {
|
||||
/// A list of users to ignore.
|
||||
#[serde(with = "ruma_serde::vec_as_map_of_empty")]
|
||||
|
@ -366,8 +366,14 @@ where
|
||||
/// Marker trait for the content of an ephemeral room event.
|
||||
pub trait EphemeralRoomEventContent: EventContent {}
|
||||
|
||||
/// Marker trait for the content of a basic event.
|
||||
pub trait BasicEventContent: EventContent {}
|
||||
/// Marker trait for the content of a global account data event.
|
||||
pub trait GlobalAccountDataEventContent: EventContent {}
|
||||
|
||||
/// Marker trait for the content of a room account data event.
|
||||
pub trait RoomAccountDataEventContent: EventContent {}
|
||||
|
||||
/// Marker trait for the content of a to device event.
|
||||
pub trait ToDeviceEventContent: EventContent {}
|
||||
|
||||
/// Marker trait for the content of a room event.
|
||||
pub trait RoomEventContent: EventContent {}
|
||||
|
@ -11,7 +11,7 @@ pub type PushRulesEvent = GlobalAccountDataEvent<PushRulesEventContent>;
|
||||
|
||||
/// The payload for `PushRulesEvent`.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||
#[ruma_event(type = "m.push_rules")]
|
||||
#[ruma_event(type = "m.push_rules", kind = GlobalAccountData)]
|
||||
pub struct PushRulesEventContent {
|
||||
/// The global ruleset.
|
||||
pub global: Ruleset,
|
||||
|
@ -17,7 +17,7 @@ pub type Tags = BTreeMap<TagName, TagInfo>;
|
||||
/// The payload for `TagEvent`.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||
#[ruma_event(type = "m.tag")]
|
||||
#[ruma_event(type = "m.tag", kind = RoomAccountData)]
|
||||
pub struct TagEventContent {
|
||||
/// A map of tag names to tag info.
|
||||
pub tags: Tags,
|
||||
|
Loading…
x
Reference in New Issue
Block a user