zoe_app_primitives/group/
events.rs1use forward_compatible_enum::ForwardCompatibleEnum;
2use serde::{Deserialize, Serialize, de::DeserializeOwned};
3
4use super::roles::GroupRole;
5use crate::{IdentityInfo, IdentityRef, Metadata};
6
7pub mod join_info;
8pub mod key_info;
9pub mod permissions;
10pub mod roles;
11pub mod settings;
12
13pub use join_info::*;
14pub use key_info::*;
15pub use permissions::*;
16pub use settings::*;
17
18#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
23pub struct CreateGroup(GroupInfo);
24
25#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
26pub struct GroupInfo {
27 pub name: String,
29 pub settings: GroupSettings,
31 pub key_info: GroupKeyInfo,
34 pub metadata: Vec<Metadata>,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
39#[serde(bound(deserialize = "T: DeserializeOwned", serialize = "T : Serialize"))]
40pub struct GroupEvent<T> {
41 idenitity: IdentityRef,
43 event: Box<GroupActivityEvent<T>>,
45}
46
47#[derive(Debug, Clone, PartialEq, ForwardCompatibleEnum)]
48#[forward_compatible(
49 serde_serialize = "T: Serialize",
50 serde_deserialize = "T: DeserializeOwned"
51)]
52pub enum GroupActivityEvent<T> {
53 #[discriminant(0)]
54 Activity(T),
55
56 #[discriminant(1)]
58 UpdateGroup(GroupInfo),
59
60 #[discriminant(2)]
62 SetIdentity(IdentityInfo),
63
64 #[discriminant(3)]
66 LeaveGroup {
67 message: Option<String>,
69 },
70
71 #[discriminant(4)]
75 AssignRole {
76 target: IdentityRef,
78 role: GroupRole,
80 },
81
82 #[discriminant(5)]
83 RemoveFromGroup {
84 target: IdentityRef,
86 },
87
88 Unknown { discriminant: u32, data: Vec<u8> },
90}
91
92impl CreateGroup {
93 pub fn new(group_info: GroupInfo) -> Self {
95 Self(group_info)
96 }
97
98 pub fn group_info(&self) -> &GroupInfo {
100 &self.0
101 }
102
103 pub fn into_group_info(self) -> GroupInfo {
105 self.0
106 }
107}