Skip to main content

zaun_community_protocol/command/
invite.rs

1//! Invitation commands (specification §8.6, permissions §4.7).
2
3mod validate;
4
5use serde::{Deserialize, Serialize};
6
7use super::check;
8use super::object::{
9    AdmissionOverrides, Cursors, InviteLink, InviteSummary, InviteUse, NewProfile,
10};
11use crate::ids::{ChannelId, CommunityId, InviteId, InviteSecret, MemberId, RoleId};
12use crate::json::SignedJson;
13use crate::keys::PublicKey;
14use crate::model::MembershipState;
15
16/// `invite.create` (§8.6).
17#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
18pub struct Create {
19    /// The channel the invitation opens on.
20    #[serde(default, skip_serializing_if = "Option::is_none")]
21    pub channel_id: Option<ChannelId>,
22    /// 0 = unlimited, else ≤ 100 000.
23    pub max_uses: u32,
24    /// Lifetime in seconds (1–2 592 000); `null` = never. Required.
25    #[serde(deserialize_with = "check::nullable::deserialize")]
26    pub expires_in_s: Option<u64>,
27    /// Roles applied when the member leaves `pending`; never `@everyone`.
28    #[serde(default, skip_serializing_if = "Option::is_none")]
29    pub default_role_ids: Option<Vec<RoleId>>,
30    /// Joins through it start `pending`.
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub requires_approval: Option<bool>,
33    /// Skip the approval queue (needs `APPROVE_MEMBERS`); conflicts with `requires_approval`.
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub pre_approved: Option<bool>,
36    /// Record the actor as sponsor.
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub sponsored: Option<bool>,
39    /// Stricter-only admission settings.
40    #[serde(default, skip_serializing_if = "Option::is_none")]
41    pub admission_overrides: Option<AdmissionOverrides>,
42}
43
44/// `invite.create` response. `link` embeds the secret and is shown once.
45#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
46pub struct Created {
47    /// Public handle.
48    pub invite_id: InviteId,
49    /// `zaun://join/…`; redacted in `Debug`.
50    pub link: InviteLink,
51    /// Expiry, ms; none = never.
52    pub expires_at: Option<u64>,
53    /// 0 = unlimited.
54    pub max_uses: u32,
55}
56
57/// `invite.redeem` (§8.6). Unbound; the envelope's `community_id` names the target.
58#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
59pub struct Redeem {
60    /// The secret from the link; redacted in `Debug`.
61    pub invite_secret: InviteSecret,
62    /// The joining member's key.
63    pub member_public_key: PublicKey,
64    /// Signed `MemberKeyRegistration`, purpose 2.
65    pub registration: SignedJson,
66    /// The joining member's display profile.
67    pub profile: NewProfile,
68}
69
70/// `invite.redeem` and `membership.request` response (§8.6, §8.9: the same shape).
71#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
72pub struct Admitted {
73    /// The community the member joined or requested to join.
74    pub community_id: CommunityId,
75    /// The new member id.
76    pub member_id: MemberId,
77    /// `pending`, `probation` or `active`.
78    pub state: MembershipState,
79    /// Signed descriptor; absent when it is the one the session's welcome gave or confirmed
80    /// (§6.2).
81    #[serde(default, skip_serializing_if = "Option::is_none")]
82    pub descriptor: Option<SignedJson>,
83    /// Signed delegation; absent with the descriptor.
84    #[serde(default, skip_serializing_if = "Option::is_none")]
85    pub delegation: Option<SignedJson>,
86    /// Initial cursors.
87    pub cursors: Cursors,
88}
89
90/// `invite.revoke` (§8.6).
91#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
92pub struct Revoke {
93    /// The invitation.
94    pub invite_id: InviteId,
95}
96
97/// `invite.list` (§8.6).
98#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
99pub struct List {
100    /// Page start (exclusive).
101    #[serde(default, skip_serializing_if = "Option::is_none")]
102    pub after: Option<InviteId>,
103    /// 1–100.
104    pub limit: u32,
105}
106
107/// `invite.list` response.
108#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
109pub struct Page {
110    /// All invitations (`MANAGE_INVITES`) or the caller's own.
111    pub invites: Vec<InviteSummary>,
112    /// The `after` of the next page; absent on the last page.
113    #[serde(default, skip_serializing_if = "Option::is_none")]
114    pub next: Option<InviteId>,
115}
116
117/// `invite.uses` (§8.6). Page size 1–100 (§12).
118#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
119pub struct Uses {
120    /// The invitation.
121    pub invite_id: InviteId,
122    /// Page start (exclusive).
123    #[serde(default, skip_serializing_if = "Option::is_none")]
124    pub after: Option<MemberId>,
125    /// 1–100.
126    pub limit: u32,
127}
128
129/// `invite.uses` response.
130#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
131pub struct UsePage {
132    /// Members admitted through the invitation.
133    pub members: Vec<InviteUse>,
134    /// The `after` of the next page; absent on the last page.
135    #[serde(default, skip_serializing_if = "Option::is_none")]
136    pub next: Option<MemberId>,
137}