Skip to main content

chat_system/
message.rs

1//! Core message types.
2
3use serde::{Deserialize, Serialize};
4
5/// A single emoji reaction attached to a message, with an aggregate count and
6/// the list of user IDs who reacted.
7///
8/// `user_ids` may be empty on platforms that only expose aggregate counts.
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10pub struct Reaction {
11    /// The emoji (Unicode character or platform-specific shortcode).
12    pub emoji: String,
13    /// Number of users who added this reaction.
14    pub count: u32,
15    /// IDs of the users who reacted (may be empty if the platform does not expose them).
16    #[serde(default)]
17    pub user_ids: Vec<String>,
18}
19
20/// A message received from or sent to a chat platform.
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct Message {
23    pub id: String,
24    pub sender: String,
25    pub content: String,
26    pub timestamp: i64,
27    #[serde(default)]
28    pub channel: Option<String>,
29    /// ID of the message this is replying to, if any.
30    #[serde(default)]
31    pub reply_to: Option<String>,
32    #[serde(default)]
33    pub media: Option<Vec<MediaAttachment>>,
34    #[serde(default)]
35    pub is_direct: bool,
36    /// Reactions attached to this message (populated when receiving messages on
37    /// platforms that expose them; `None` means unknown / not fetched).
38    #[serde(default)]
39    pub reactions: Option<Vec<Reaction>>,
40}
41
42/// A media attachment in a message.
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct MediaAttachment {
45    pub url: Option<String>,
46    pub path: Option<String>,
47    pub mime_type: Option<String>,
48    pub filename: Option<String>,
49}
50
51/// Options for sending a message with additional metadata.
52#[derive(Debug, Default)]
53pub struct SendOptions<'a> {
54    pub recipient: &'a str,
55    pub content: &'a str,
56    pub reply_to: Option<&'a str>,
57    pub silent: bool,
58    pub media: Option<&'a str>,
59}