tetratto-core 18.0.1

The core behind Tetratto
Documentation
use serde::{Serialize, Deserialize};
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Default)]
pub enum StackPrivacy {
    /// Can be viewed by anyone.
    Public,
    /// Can only be viewed by the stack's owner (and users with `MANAGE_STACKS`).
    #[default]
    Private,
}


#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Default)]
pub enum StackMode {
    /// `users` vec contains ID of users to INCLUDE into the timeline;
    /// every other user is excluded
    #[default]
    Include,
    /// `users` vec contains ID of users to EXCLUDE from the timeline;
    /// every other user is included
    Exclude,
    /// `users` vec contains ID of users to show in a user listing on the stack's
    /// page (instead of a timeline).
    ///
    /// Other users can block the entire list (creating a `StackBlock`, not a `UserBlock`).
    BlockList,
    /// `users` vec contains ID of users who are allowed to view posts posted to the stack.
    Circle,
}


#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Default)]
pub enum StackSort {
    #[default]
    Created,
    Likes,
}


#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct UserStack {
    pub id: usize,
    pub created: usize,
    pub owner: usize,
    pub name: String,
    pub users: Vec<usize>,
    pub privacy: StackPrivacy,
    pub mode: StackMode,
    pub sort: StackSort,
    /// Locked stacks cannot be deleted or have their mode changed. Stacks cannot
    /// be locked after creation, and must be locked by the server.
    pub is_locked: bool,
}

impl UserStack {
    /// Create a new [`UserStack`].
    pub fn new(name: String, owner: usize, users: Vec<usize>) -> Self {
        Self {
            id: Snowflake::new().to_string().parse::<usize>().unwrap(),
            created: unix_epoch_timestamp(),
            owner,
            name,
            users,
            privacy: StackPrivacy::default(),
            mode: StackMode::default(),
            sort: StackSort::default(),
            is_locked: false,
        }
    }
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct StackBlock {
    pub id: usize,
    pub created: usize,
    pub initiator: usize,
    pub stack: usize,
}

impl StackBlock {
    /// Create a new [`StackBlock`].
    pub fn new(initiator: usize, stack: usize) -> Self {
        Self {
            id: Snowflake::new().to_string().parse::<usize>().unwrap(),
            created: unix_epoch_timestamp(),
            initiator,
            stack,
        }
    }
}