tetratto/crates/core/src/model/stacks.rs
2025-06-15 11:52:44 -04:00

97 lines
2.4 KiB
Rust

use serde::{Serialize, Deserialize};
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum StackPrivacy {
/// Can be viewed by anyone.
Public,
/// Can only be viewed by the stack's owner (and users with `MANAGE_STACKS`).
Private,
}
impl Default for StackPrivacy {
fn default() -> Self {
Self::Private
}
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum StackMode {
/// `users` vec contains ID of users to INCLUDE into the timeline;
/// every other user is excluded
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,
}
impl Default for StackMode {
fn default() -> Self {
Self::Include
}
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum StackSort {
Created,
Likes,
}
impl Default for StackSort {
fn default() -> Self {
Self::Created
}
}
#[derive(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,
}
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(),
}
}
}
#[derive(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,
}
}
}