zaun_community_protocol/event/body/message.rs
1//! Channel-stream event bodies (§9.2). The channel, sequence and time are envelope fields.
2
3use serde::{Deserialize, Serialize};
4
5use crate::command::object::{Attachment, Component, Embed, InteractionMetadata, Mentions};
6use crate::ids::{MemberId, MessageId};
7
8/// `message.created` (§7.4, §9.2).
9///
10/// SPEC: §9.2 says "message object", but the §7.4 example body has only `message_id`,
11/// `author_id`, `content`, `reply_to`, `mentions` and `attachments`; `channel_id`,
12/// `sequence` and `created_at` are on the envelope, and a new message has no reactions. This
13/// type follows §7.4; a host sending the full §8.5 object still parses (extra fields are
14/// ignored).
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct MessageCreated {
17 /// Host-assigned id.
18 pub message_id: MessageId,
19 /// The author.
20 pub author_id: MemberId,
21 /// ≤ 4 000 scalars; empty only when the message has an attachment or an embed.
22 pub content: String,
23 /// Rich embeds; absent when none.
24 #[serde(default, skip_serializing_if = "Vec::is_empty")]
25 pub embeds: Vec<Embed>,
26 /// Components (bots only); absent when none.
27 #[serde(default, skip_serializing_if = "Vec::is_empty")]
28 pub components: Vec<Component>,
29 /// Message flags; absent when 0.
30 #[serde(default, skip_serializing_if = "crate::json::is_zero_u32")]
31 pub flags: u32,
32 /// The interaction this message answers.
33 #[serde(default, skip_serializing_if = "Option::is_none")]
34 pub interaction_metadata: Option<Box<InteractionMetadata>>,
35 /// The message replied to.
36 #[serde(default)]
37 pub reply_to: Option<MessageId>,
38 /// Who is mentioned (as honoured by the host).
39 #[serde(default)]
40 pub mentions: Mentions,
41 /// Attachments, in the order the author listed them.
42 #[serde(default)]
43 pub attachments: Vec<Attachment>,
44}
45
46/// `message.updated`: `{message_id, content, embeds?, components?, flags?, mentions?, edited_at}`.
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
48pub struct MessageUpdated {
49 /// The message.
50 pub message_id: MessageId,
51 /// New content.
52 pub content: String,
53 /// As in `message.edit`: absent when the edit left the embeds unchanged, else the
54 /// message's new embeds (`[]` when the edit removed them all).
55 #[serde(default, skip_serializing_if = "Option::is_none")]
56 pub embeds: Option<Vec<Embed>>,
57 /// As `embeds`, for components.
58 #[serde(default, skip_serializing_if = "Option::is_none")]
59 pub components: Option<Vec<Component>>,
60 /// The new flags, when they changed (a deferred reply loses `LOADING`).
61 #[serde(default, skip_serializing_if = "Option::is_none")]
62 pub flags: Option<u32>,
63 /// As `embeds`, for mentions: the ones the host honoured, absent when the edit left them
64 /// unchanged.
65 #[serde(default, skip_serializing_if = "Option::is_none")]
66 pub mentions: Option<Mentions>,
67 /// Edit time, ms.
68 pub edited_at: u64,
69}
70
71/// `message.deleted`: `{message_id}`.
72#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
73pub struct MessageDeleted {
74 /// The message.
75 pub message_id: MessageId,
76}
77
78/// `messages.bulk_deleted`: `{message_ids}` (≤ 1 000).
79#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
80pub struct MessagesBulkDeleted {
81 /// The deleted messages.
82 pub message_ids: Vec<MessageId>,
83}
84
85/// `reaction.added` and `reaction.removed`: `{message_id, emoji, member_id}`.
86#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
87pub struct ReactionChanged {
88 /// The message.
89 pub message_id: MessageId,
90 /// The emoji.
91 pub emoji: String,
92 /// Whose reaction.
93 pub member_id: MemberId,
94}