vitium_api/
chat.rs

1use serde::{Deserialize, Serialize};
2
3/// A global out-game chat message.
4///
5/// # Time Order
6///
7/// The [`Self::sender`] fields indicates the local timestamp on the client when and where this message is sent.
8/// No guarantee is made about the consistency of the time order of message.
9///
10/// # HTML
11///
12/// The message can either be a plain text message (when [`Self::html`] is set to `false`)
13/// or an HTML message (when [`Self::html`] is set to `true`).
14///
15/// ## Caution
16///
17/// Only constrait to [`Self::content`] is the same as that of [`String`], i.e. to be valid UTF-8,
18/// even if [`Self::html`] is on.
19/// Therefore, no guarantee is made about whether it is valid DOM element or HTML.
20/// Appropriate checks shall be done before attempting to render HTML to avoid potential danger.
21#[derive(Clone, Serialize, Deserialize)]
22#[cfg_attr(target_family = "wasm", derive(tsify_next::Tsify))]
23#[cfg_attr(
24    target_family = "wasm",
25    tsify(
26        into_wasm_abi,
27        from_wasm_abi,
28        missing_as_null,
29        large_number_types_as_bigints
30    )
31)]
32pub struct Message {
33    /// Milisecond UNIX timestamp when the message is sent.
34    #[cfg(target_family = "wasm")] // walkaround for json missing bigint support
35    pub time: f64,
36    /// Milisecond UNIX timestamp when the message is sent.
37    #[cfg(not(target_family = "wasm"))]
38    pub time: u64,
39    /// The user who sends the message.
40    ///
41    /// A [`None`] indicates that this message is a broadcast triggered by a server command.
42    pub sender: Option<String>,
43    /// Content of the chat.
44    /// This field shall be interpreted with respect to [`Self::html`] as plain text or string of HTML.
45    pub content: String,
46    /// Whether HTML is enabled in the content of the message.
47    pub html: bool,
48}