tetratto_core/model/
stacks.rs

1use serde::{Serialize, Deserialize};
2use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
3
4#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
5pub enum StackPrivacy {
6    /// Can be viewed by anyone.
7    Public,
8    /// Can only be viewed by the stack's owner (and users with `MANAGE_STACKS`).
9    Private,
10}
11
12impl Default for StackPrivacy {
13    fn default() -> Self {
14        Self::Private
15    }
16}
17
18#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
19pub enum StackMode {
20    /// `users` vec contains ID of users to INCLUDE into the timeline;
21    /// every other user is excluded
22    Include,
23    /// `users` vec contains ID of users to EXCLUDE from the timeline;
24    /// every other user is included
25    Exclude,
26    /// `users` vec contains ID of users to show in a user listing on the stack's
27    /// page (instead of a timeline).
28    ///
29    /// Other users can block the entire list (creating a `StackBlock`, not a `UserBlock`).
30    BlockList,
31    /// `users` vec contains ID of users who are allowed to view posts posted to the stack.
32    Circle,
33}
34
35impl Default for StackMode {
36    fn default() -> Self {
37        Self::Include
38    }
39}
40
41#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
42pub enum StackSort {
43    Created,
44    Likes,
45}
46
47impl Default for StackSort {
48    fn default() -> Self {
49        Self::Created
50    }
51}
52
53#[derive(Clone, Debug, Serialize, Deserialize)]
54pub struct UserStack {
55    pub id: usize,
56    pub created: usize,
57    pub owner: usize,
58    pub name: String,
59    pub users: Vec<usize>,
60    pub privacy: StackPrivacy,
61    pub mode: StackMode,
62    pub sort: StackSort,
63}
64
65impl UserStack {
66    /// Create a new [`UserStack`].
67    pub fn new(name: String, owner: usize, users: Vec<usize>) -> Self {
68        Self {
69            id: Snowflake::new().to_string().parse::<usize>().unwrap(),
70            created: unix_epoch_timestamp(),
71            owner,
72            name,
73            users,
74            privacy: StackPrivacy::default(),
75            mode: StackMode::default(),
76            sort: StackSort::default(),
77        }
78    }
79}
80
81#[derive(Clone, Debug, Serialize, Deserialize)]
82pub struct StackBlock {
83    pub id: usize,
84    pub created: usize,
85    pub initiator: usize,
86    pub stack: usize,
87}
88
89impl StackBlock {
90    /// Create a new [`StackBlock`].
91    pub fn new(initiator: usize, stack: usize) -> Self {
92        Self {
93            id: Snowflake::new().to_string().parse::<usize>().unwrap(),
94            created: unix_epoch_timestamp(),
95            initiator,
96            stack,
97        }
98    }
99}