1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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,
}
}
}