add: user stacks

This commit is contained in:
trisua 2025-05-08 22:18:04 -04:00
parent 8c3024cb40
commit 75d72460ae
28 changed files with 1028 additions and 9 deletions

View file

@ -6,6 +6,7 @@ pub mod oauth;
pub mod permissions;
pub mod reactions;
pub mod requests;
pub mod stacks;
pub mod uploads;
#[cfg(feature = "redis")]

View file

@ -34,6 +34,7 @@ bitflags! {
const MANAGE_MESSAGES = 1 << 23;
const MANAGE_UPLOADS = 1 << 24;
const MANAGE_EMOJIS = 1 << 25;
const MANAGE_STACKS = 1 << 26;
const _ = !0;
}

View file

@ -0,0 +1,40 @@
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(Serialize, Deserialize)]
pub struct UserStack {
pub id: usize,
pub created: usize,
pub owner: usize,
pub name: String,
pub users: Vec<usize>,
pub privacy: StackPrivacy,
}
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(),
}
}
}