rive_models/
message.rs

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/// Channel message
8#[derive(Deserialize, Debug, Clone)]
9pub struct Message {
10    /// Unique message ID
11    #[serde(rename = "_id")]
12    pub id: String,
13
14    /// Unique value generated by client sending this message
15    pub nonce: Option<String>,
16
17    /// ID of the channel this message was sent in
18    pub channel: String,
19
20    /// ID of the user that sent this message
21    pub author: String,
22
23    /// Message content
24    pub content: Option<String>,
25
26    /// System message
27    pub system: Option<SystemMessage>,
28
29    /// Array of attachments
30    pub attachments: Option<Vec<Attachment>>,
31
32    /// Time at which this message was last edited
33    pub edited: Option<Timestamp>,
34
35    /// Attached embeds to this message
36    pub embeds: Option<Vec<Embed>>,
37
38    /// Array of user ids mentioned in this message
39    pub mentions: Option<Vec<String>>,
40
41    /// Array of message ids this message is replying to
42    pub replies: Option<Vec<String>>,
43
44    /// Hashmap of emoji IDs to array of user IDs
45    #[serde(default)]
46    pub reactions: HashMap<String, HashSet<String>>,
47
48    /// Information about how this message should be interacted with
49    #[serde(default)]
50    pub interactions: Interactions,
51
52    /// Name and / or avatar overrides for this message
53    pub masquerade: Option<Masquerade>,
54}
55
56///Partial channel message
57#[derive(Deserialize, Debug, Clone)]
58pub struct PartialMessage {
59    /// Unique message ID
60    #[serde(rename = "_id")]
61    pub id: Option<String>,
62
63    /// Unique value generated by client sending this message
64    pub nonce: Option<String>,
65
66    /// ID of the channel this message was sent in
67    pub channel: Option<String>,
68
69    /// ID of the user that sent this message
70    pub author: Option<String>,
71
72    /// Message content
73    pub content: Option<String>,
74
75    /// System message
76    pub system: Option<SystemMessage>,
77
78    /// Array of attachments
79    pub attachments: Option<Vec<Attachment>>,
80
81    /// Time at which this message was last edited
82    pub edited: Option<Timestamp>,
83
84    /// Attached embeds to this message
85    pub embeds: Option<Vec<Embed>>,
86
87    /// Array of user ids mentioned in this message
88    pub mentions: Option<Vec<String>>,
89
90    /// Array of message ids this message is replying to
91    pub replies: Option<Vec<String>>,
92
93    /// Hashmap of emoji IDs to array of user IDs
94    pub reactions: Option<HashMap<String, HashSet<String>>>,
95
96    /// Information about how this message should be interacted with
97    pub interactions: Option<Interactions>,
98
99    /// Name and / or avatar overrides for this message
100    pub masquerade: Option<Masquerade>,
101}
102
103/// Information to guide interactions on this message
104#[derive(Serialize, Deserialize, Debug, Clone, Default)]
105pub struct Interactions {
106    /// Reactions which should always appear and be distinct
107    #[serde(skip_serializing_if = "Option::is_none", default)]
108    pub reactions: Option<HashSet<String>>,
109    /// Whether reactions should be restricted to the given list
110    #[serde(default)]
111    pub restrict_reactions: bool,
112}
113
114#[derive(Serialize, Deserialize, Debug, Clone)]
115pub struct Masquerade {
116    /// Replace the display name shown on this message
117    #[serde(skip_serializing_if = "Option::is_none")]
118    pub name: Option<String>,
119
120    /// Replace the avatar shown on this message (URL to image file)
121    #[serde(skip_serializing_if = "Option::is_none")]
122    pub avatar: Option<String>,
123
124    /// Replace the display role colour shown on this message
125    ///
126    /// Must have `ManageRole` permission to use
127    ///
128    /// This can be any valid CSS colour
129    #[serde(skip_serializing_if = "Option::is_none")]
130    pub colour: Option<String>,
131}
132
133/// System message type
134#[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/// Sort used for retrieving messages
151#[derive(Serialize, Deserialize, Debug, Clone)]
152pub enum MessageSort {
153    /// Sort by the most relevant messages
154    Relevance,
155    /// Sort by the newest messages first
156    Latest,
157    /// Sort by the oldest messages first
158    Oldest,
159}
160
161/// Appended Information
162#[derive(Deserialize, Debug, Clone)]
163pub struct AppendMessage {
164    /// Additional embeds to include in this message
165    pub embeds: Option<Vec<Embed>>,
166}
167
168/// Response used when multiple messages are fetched
169#[derive(Deserialize, Debug, Clone)]
170#[serde(untagged)]
171pub enum BulkMessageResponse {
172    JustMessages(
173        /// List of messages
174        Vec<Message>,
175    ),
176    MessagesAndUsers {
177        /// List of messages
178        messages: Vec<Message>,
179        /// List of users
180        users: Vec<User>,
181        /// List of members
182        members: Option<Vec<Member>>,
183    },
184}
185
186/// Representation of a message reply before it is sent
187#[derive(Serialize, Clone, Debug)]
188pub struct Reply {
189    /// Message ID
190    pub id: String,
191    /// Whether this reply should mention the message's author
192    pub mention: bool,
193}