tetratto_core2/model/
groups.rs1use super::id::Id;
2use serde::{Deserialize, Serialize};
3use tritools::time::unix_epoch_timestamp;
4use serde_valid::Validate;
5
6#[derive(Clone, Debug, Serialize, Deserialize, Default, Validate)]
7pub struct GroupSettings {
8 #[serde(default)]
9 pub require_approval: bool,
10 #[validate(min_length = 0)]
11 #[validate(max_length = 4096)]
12 #[serde(default)]
13 pub biography: String,
14}
15
16#[derive(Serialize, Deserialize, Clone)]
17pub struct Group {
18 pub id: Id,
19 pub created: u128,
20 pub owner: Id,
21 pub name: String,
22 pub settings: GroupSettings,
23 pub members: i32,
24}
25
26impl Group {
27 pub fn new(owner: Id, name: String) -> Self {
29 Self {
30 id: Id::new(),
31 created: unix_epoch_timestamp(),
32 owner,
33 name,
34 settings: GroupSettings::default(),
35 members: 0,
36 }
37 }
38}
39
40#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
41pub enum GroupRole {
42 Owner,
43 #[default]
44 Member,
45 Banned,
46 Pending,
47}
48
49#[derive(Clone, Debug, Serialize, Deserialize)]
50pub struct GroupMembership {
51 pub id: Id,
52 pub created: u128,
53 pub owner: Id,
54 pub group: Id,
55 pub role: GroupRole,
56}
57
58impl GroupMembership {
59 pub fn new(owner: Id, group: Id, role: GroupRole) -> Self {
61 Self {
62 id: Id::new(),
63 created: unix_epoch_timestamp(),
64 owner,
65 group,
66 role,
67 }
68 }
69
70 pub fn owner() -> Self {
71 Self {
72 id: Id::Legacy(0),
73 created: 0,
74 owner: Id::Legacy(0),
75 group: Id::Legacy(0),
76 role: GroupRole::Owner,
77 }
78 }
79}