ruma_events/
_custom.rs
1use ruma_common::room_version_rules::RedactionRules;
2use serde::Serialize;
3use serde_json::value::RawValue as RawJsonValue;
4
5use super::{
6 EphemeralRoomEventContent, EphemeralRoomEventType, EventContent, EventContentFromType,
7 GlobalAccountDataEventContent, GlobalAccountDataEventType, MessageLikeEventContent,
8 MessageLikeEventType, MessageLikeUnsigned, PossiblyRedactedStateEventContent, RedactContent,
9 RedactedMessageLikeEventContent, RedactedStateEventContent, RoomAccountDataEventContent,
10 RoomAccountDataEventType, StateEventContent, StateEventType, StaticStateEventContent,
11 ToDeviceEventContent, ToDeviceEventType,
12};
13
14macro_rules! custom_event_content {
15 ($i:ident, $evt:ident) => {
16 #[derive(Clone, Debug, Serialize)]
20 #[allow(clippy::exhaustive_structs)]
21 pub struct $i {
22 #[serde(skip)]
23 event_type: Box<str>,
24 }
25
26 impl EventContent for $i {
27 type EventType = $evt;
28
29 fn event_type(&self) -> Self::EventType {
30 self.event_type[..].into()
31 }
32 }
33
34 impl EventContentFromType for $i {
35 fn from_parts(event_type: &str, _content: &RawJsonValue) -> serde_json::Result<Self> {
36 Ok(Self { event_type: event_type.into() })
37 }
38 }
39 };
40}
41
42macro_rules! custom_room_event_content {
43 ($i:ident, $evt:ident) => {
44 custom_event_content!($i, $evt);
45
46 impl RedactContent for $i {
47 type Redacted = Self;
48
49 fn redact(self, _: &RedactionRules) -> Self {
50 self
51 }
52 }
53 };
54}
55
56custom_event_content!(CustomGlobalAccountDataEventContent, GlobalAccountDataEventType);
57impl GlobalAccountDataEventContent for CustomGlobalAccountDataEventContent {}
58
59custom_event_content!(CustomRoomAccountDataEventContent, RoomAccountDataEventType);
60impl RoomAccountDataEventContent for CustomRoomAccountDataEventContent {}
61
62custom_event_content!(CustomEphemeralRoomEventContent, EphemeralRoomEventType);
63impl EphemeralRoomEventContent for CustomEphemeralRoomEventContent {}
64
65custom_room_event_content!(CustomMessageLikeEventContent, MessageLikeEventType);
66impl MessageLikeEventContent for CustomMessageLikeEventContent {}
67impl RedactedMessageLikeEventContent for CustomMessageLikeEventContent {}
68
69custom_room_event_content!(CustomStateEventContent, StateEventType);
70impl StateEventContent for CustomStateEventContent {
71 type StateKey = String;
72}
73impl StaticStateEventContent for CustomStateEventContent {
74 type Unsigned = MessageLikeUnsigned<CustomMessageLikeEventContent>;
78 type PossiblyRedacted = Self;
79}
80impl PossiblyRedactedStateEventContent for CustomStateEventContent {
81 type StateKey = String;
82}
83impl RedactedStateEventContent for CustomStateEventContent {
84 type StateKey = String;
85}
86
87custom_event_content!(CustomToDeviceEventContent, ToDeviceEventType);
88impl ToDeviceEventContent for CustomToDeviceEventContent {}