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