1use iso8601_timestamp::Timestamp;
2use serde::{Deserialize, Serialize};
3use std::collections::{HashMap, HashSet};
4
5use crate::{attachment::Attachment, embed::Embed, member::Member, user::User};
6
7#[derive(Deserialize, Debug, Clone)]
9pub struct Message {
10 #[serde(rename = "_id")]
12 pub id: String,
13
14 pub nonce: Option<String>,
16
17 pub channel: String,
19
20 pub author: String,
22
23 pub content: Option<String>,
25
26 pub system: Option<SystemMessage>,
28
29 pub attachments: Option<Vec<Attachment>>,
31
32 pub edited: Option<Timestamp>,
34
35 pub embeds: Option<Vec<Embed>>,
37
38 pub mentions: Option<Vec<String>>,
40
41 pub replies: Option<Vec<String>>,
43
44 #[serde(default)]
46 pub reactions: HashMap<String, HashSet<String>>,
47
48 #[serde(default)]
50 pub interactions: Interactions,
51
52 pub masquerade: Option<Masquerade>,
54}
55
56#[derive(Deserialize, Debug, Clone)]
58pub struct PartialMessage {
59 #[serde(rename = "_id")]
61 pub id: Option<String>,
62
63 pub nonce: Option<String>,
65
66 pub channel: Option<String>,
68
69 pub author: Option<String>,
71
72 pub content: Option<String>,
74
75 pub system: Option<SystemMessage>,
77
78 pub attachments: Option<Vec<Attachment>>,
80
81 pub edited: Option<Timestamp>,
83
84 pub embeds: Option<Vec<Embed>>,
86
87 pub mentions: Option<Vec<String>>,
89
90 pub replies: Option<Vec<String>>,
92
93 pub reactions: Option<HashMap<String, HashSet<String>>>,
95
96 pub interactions: Option<Interactions>,
98
99 pub masquerade: Option<Masquerade>,
101}
102
103#[derive(Serialize, Deserialize, Debug, Clone, Default)]
105pub struct Interactions {
106 #[serde(skip_serializing_if = "Option::is_none", default)]
108 pub reactions: Option<HashSet<String>>,
109 #[serde(default)]
111 pub restrict_reactions: bool,
112}
113
114#[derive(Serialize, Deserialize, Debug, Clone)]
115pub struct Masquerade {
116 #[serde(skip_serializing_if = "Option::is_none")]
118 pub name: Option<String>,
119
120 #[serde(skip_serializing_if = "Option::is_none")]
122 pub avatar: Option<String>,
123
124 #[serde(skip_serializing_if = "Option::is_none")]
130 pub colour: Option<String>,
131}
132
133#[derive(Deserialize, Debug, Clone)]
135#[serde(tag = "type", rename_all = "snake_case")]
136pub enum SystemMessage {
137 Text { content: String },
138 UserAdded { id: String, by: String },
139 UserRemove { id: String, by: String },
140 UserJoined { id: String },
141 UserLeft { id: String },
142 UserKicked { id: String },
143 UserBanned { id: String },
144 ChannelRenamed { name: String, by: String },
145 ChannelDescriptionChanged { by: String },
146 ChannelIconChanged { by: String },
147 ChannelOwnershipChanged { from: String, to: String },
148}
149
150#[derive(Serialize, Deserialize, Debug, Clone)]
152pub enum MessageSort {
153 Relevance,
155 Latest,
157 Oldest,
159}
160
161#[derive(Deserialize, Debug, Clone)]
163pub struct AppendMessage {
164 pub embeds: Option<Vec<Embed>>,
166}
167
168#[derive(Deserialize, Debug, Clone)]
170#[serde(untagged)]
171pub enum BulkMessageResponse {
172 JustMessages(
173 Vec<Message>,
175 ),
176 MessagesAndUsers {
177 messages: Vec<Message>,
179 users: Vec<User>,
181 members: Option<Vec<Member>>,
183 },
184}
185
186#[derive(Serialize, Clone, Debug)]
188pub struct Reply {
189 pub id: String,
191 pub mention: bool,
193}