//! Field types. // TODO Add newtype wrappers for different kinds of IDs? // Serde's derive macros generate this warning and I can't turn it off locally, // so I'm turning it off for the entire module. #![allow(clippy::use_self)] use std::num::ParseIntError; use std::str::FromStr; use std::{error, fmt}; use jiff::Timestamp; use serde::{de, ser, Deserialize, Serialize}; use serde_json::Value; /// Describes an account and its preferred name. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AccountView { /// The id of the account. pub id: AccountId, /// The name that the holder of the account goes by. pub name: String, } /// Mode of authentication. #[derive(Debug, Clone, Copy, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub enum AuthOption { /// Authentication with a passcode, where a key is derived from the passcode /// to unlock an access grant. Passcode, } /// A node in a room's log. /// /// It corresponds to a chat message, or a post, or any broadcasted event in a /// room that should appear in the log. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Message { /// The id of the message (unique within a room). pub id: MessageId, /// The id of the message's parent, or null if top-level. #[serde(skip_serializing_if = "Option::is_none")] pub parent: Option, /// The edit id of the most recent edit of this message, or null if it's /// never been edited. #[serde(skip_serializing_if = "Option::is_none")] pub previous_edit_id: Option, /// The unix timestamp of when the message was posted. pub time: Time, /// The view of the sender's session. pub sender: SessionView, /// The content of the message (client-defined). pub content: String, /// The id of the key that encrypts the message in storage. #[serde(skip_serializing_if = "Option::is_none")] pub encryption_key_id: Option, /// The unix timestamp of when the message was last edited. #[serde(skip_serializing_if = "Option::is_none")] pub edited: Option