zoe_app_primitives/group/events/join_info.rs
1use serde::{Deserialize, Serialize};
2
3use super::{GroupInfo, GroupKeyInfo};
4use crate::{Metadata, RelayEndpoint};
5
6/// Complete information needed for a participant to join an encrypted group
7///
8/// This structure contains everything a new participant needs to join and
9/// participate in an encrypted group, including the group metadata, encryption
10/// keys, channel information, and relay endpoints for communication.
11#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
12pub struct GroupJoinInfo {
13 /// Hash ID of the initial CreateGroup message
14 ///
15 /// This serves as the unique channel ID for the group and is derived
16 /// from the Blake3 hash of the initial CreateGroup message.
17 pub channel_id: String,
18
19 /// Group information from the CreateGroup event
20 ///
21 /// Contains the group name, description, metadata, settings, and other
22 /// information that was specified when the group was created.
23 pub group_info: GroupInfo,
24
25 /// Encryption key for the group
26 ///
27 /// The shared AES key used to encrypt and decrypt group messages.
28 /// This is the raw key bytes that participants need to encrypt/decrypt
29 /// group communications.
30 pub encryption_key: [u8; 32],
31
32 /// Key derivation information
33 ///
34 /// Contains metadata about how the encryption key was derived,
35 /// including key ID and derivation parameters. This helps participants
36 /// identify and manage the correct encryption keys.
37 pub key_info: GroupKeyInfo,
38
39 /// List of relay endpoints (ordered by priority)
40 ///
41 /// Contains the relay servers that participants can use to communicate
42 /// within the group. The list is ordered by priority, with the first
43 /// endpoint being the preferred relay. Participants should try relays
44 /// in order until they find one that works.
45 pub relay_endpoints: Vec<RelayEndpoint>,
46
47 /// Optional invitation metadata
48 ///
49 /// Additional information about the invitation, such as who sent it,
50 /// when it was created, expiration time, or invitation-specific settings.
51 pub invitation_metadata: Vec<Metadata>,
52}
53
54impl GroupJoinInfo {
55 /// Create new group join information
56 pub fn new(
57 channel_id: String,
58 group_info: GroupInfo,
59 encryption_key: [u8; 32],
60 key_info: GroupKeyInfo,
61 relay_endpoints: Vec<RelayEndpoint>,
62 ) -> Self {
63 Self {
64 channel_id,
65 group_info,
66 encryption_key,
67 key_info,
68 relay_endpoints,
69 invitation_metadata: Vec::new(),
70 }
71 }
72
73 /// Add metadata to the invitation
74 pub fn with_invitation_metadata(mut self, metadata: Metadata) -> Self {
75 self.invitation_metadata.push(metadata);
76 self
77 }
78
79 /// Add a relay endpoint to the list
80 pub fn add_relay(mut self, endpoint: RelayEndpoint) -> Self {
81 self.relay_endpoints.push(endpoint);
82 self
83 }
84
85 /// Get the primary (first priority) relay endpoint
86 pub fn primary_relay(&self) -> Option<&RelayEndpoint> {
87 self.relay_endpoints.first()
88 }
89
90 /// Get all relay endpoints ordered by priority
91 pub fn relays_by_priority(&self) -> &[RelayEndpoint] {
92 &self.relay_endpoints
93 }
94
95 /// Check if this invitation has any relay endpoints
96 pub fn has_relays(&self) -> bool {
97 !self.relay_endpoints.is_empty()
98 }
99}