zoe_app_primitives/group/
events.rs

1use 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/// Activity events for encrypted group management in the DGA protocol
19///
20/// All events are encrypted with AES-GCM using the group's shared key.
21/// These events form the core primitives for managing distributed encrypted groups.
22#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
23pub struct CreateGroup(GroupInfo);
24
25#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
26pub struct GroupInfo {
27    /// Human-readable group name
28    pub name: String,
29    // initial group settings
30    pub settings: GroupSettings,
31    /// Key derivation info or key identifier (not the actual key)
32    /// Used to help participants derive or identify the correct AES key
33    pub key_info: GroupKeyInfo,
34    /// Optional group avatar image
35    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    /// which identity are we sending this event as
42    idenitity: IdentityRef,
43    /// the event we are sending
44    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    /// Update group metadata (name, description, settings)
57    #[discriminant(1)]
58    UpdateGroup(GroupInfo),
59
60    /// Set identity information for the sending identity
61    #[discriminant(2)]
62    SetIdentity(IdentityInfo),
63
64    /// Announce departure from group
65    #[discriminant(3)]
66    LeaveGroup {
67        /// Optional goodbye message
68        message: Option<String>,
69    },
70
71    /// Assign a role to an identity (key or key+alias)
72    ///
73    /// Requires appropriate permissions based on group settings.
74    #[discriminant(4)]
75    AssignRole {
76        /// The identity to assign a role to
77        target: IdentityRef,
78        /// The new role
79        role: GroupRole,
80    },
81
82    #[discriminant(5)]
83    RemoveFromGroup {
84        /// The identity to remove
85        target: IdentityRef,
86    },
87
88    /// Unknown management event for forward compatibility
89    Unknown { discriminant: u32, data: Vec<u8> },
90}
91
92impl CreateGroup {
93    /// Create a new CreateGroup event
94    pub fn new(group_info: GroupInfo) -> Self {
95        Self(group_info)
96    }
97
98    /// Get a reference to the inner GroupInfo
99    pub fn group_info(&self) -> &GroupInfo {
100        &self.0
101    }
102
103    /// Consume the CreateGroup and return the inner GroupInfo
104    pub fn into_group_info(self) -> GroupInfo {
105        self.0
106    }
107}