tetratto/crates/core/src/model/stacks.rs

73 lines
1.7 KiB
Rust
Raw Normal View History

2025-05-08 22:18:04 -04:00
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
}
}
2025-05-09 15:56:19 -04:00
#[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,
}
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
}
}
2025-05-08 22:18:04 -04:00
#[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,
2025-05-09 15:56:19 -04:00
pub mode: StackMode,
pub sort: StackSort,
2025-05-08 22:18:04 -04:00
}
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() as usize,
owner,
name,
users,
privacy: StackPrivacy::default(),
2025-05-09 15:56:19 -04:00
mode: StackMode::default(),
sort: StackSort::default(),
2025-05-08 22:18:04 -04:00
}
}
}