Skip to main content

zaun_community_protocol/command/
community.rs

1//! Community commands (specification §8.1).
2
3mod validate;
4
5use serde::{Deserialize, Serialize};
6
7use super::check;
8use super::object::{CommunityProfile, Cursors, NewProfile, SignedRotation};
9use crate::ids::{ChannelId, CommunityId, MemberId};
10use crate::json::{Patch, SignedJson};
11use crate::keys::PublicKey;
12pub use crate::limits::ROTATIONS_PAGE;
13
14/// `community.create` (§8.1). The envelope's `community_id` names the target.
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct Create {
17    /// Signed `CommunityDescriptor`, revision 1.
18    pub descriptor: SignedJson,
19    /// Signed `HostDelegation` naming this host.
20    pub delegation: SignedJson,
21    /// The creator's member key; MUST equal the descriptor's `owner_member_key`.
22    pub member_public_key: PublicKey,
23    /// Signed `MemberKeyRegistration`, purpose 1.
24    pub registration: SignedJson,
25    /// The creator's display profile.
26    pub profile: NewProfile,
27}
28
29/// `community.create` response.
30#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
31pub struct Created {
32    /// The community.
33    pub community_id: CommunityId,
34    /// The creator's member id.
35    pub member_id: MemberId,
36    /// Initial cursors.
37    pub cursors: Cursors,
38}
39
40/// `community.get` (`{}`).
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
42pub struct Get {}
43
44/// `community.get` response.
45#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
46pub struct Info {
47    /// Signed descriptor.
48    pub descriptor: SignedJson,
49    /// Signed delegation.
50    pub delegation: SignedJson,
51    /// Host-managed profile.
52    pub profile: CommunityProfile,
53    /// The owner's member id.
54    pub owner_id: MemberId,
55}
56
57/// `community.icon.get` (`{}`).
58#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
59pub struct IconGet {}
60
61/// `community.icon.get` response; the client checks `SHA3-256(icon)` against the descriptor.
62#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
63pub struct Icon {
64    /// PNG or WebP bytes, ≤ 49 152.
65    #[serde(with = "crate::b64::bytes")]
66    pub icon: Vec<u8>,
67}
68
69/// `community.rotations` (§8.1).
70///
71/// SPEC: `after` is written `u32` but `rotation_seq` is a `u64` (§4.6); `u64` is accepted.
72#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
73pub struct Rotations {
74    /// Return rotations with `rotation_seq` above this.
75    #[serde(default, skip_serializing_if = "Option::is_none")]
76    pub after: Option<u64>,
77    /// 1–4.
78    pub limit: u32,
79}
80
81/// `community.rotations` response.
82#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
83pub struct RotationPage {
84    /// Signed rotations in chain order.
85    pub rotations: Vec<SignedRotation>,
86    /// The `after` for the next page.
87    #[serde(default, skip_serializing_if = "Option::is_none")]
88    pub next: Option<u64>,
89}
90
91/// `community.update` (§8.1): host-managed profile fields only.
92#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
93pub struct Update {
94    /// `null` clears.
95    #[serde(default, skip_serializing_if = "Patch::is_keep")]
96    pub system_channel_id: Patch<ChannelId>,
97    /// 0–21 600; not nullable.
98    #[serde(default, skip_serializing_if = "Patch::is_keep")]
99    pub default_slowmode_s: Patch<u32>,
100}
101
102/// `community.update` response.
103#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
104pub struct ProfileResponse {
105    /// The updated profile.
106    pub profile: CommunityProfile,
107}
108
109/// `community.descriptor.publish` (§8.1). Owner only; larger envelope limit (§12).
110#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
111pub struct DescriptorPublish {
112    /// The new signed descriptor (revision > current).
113    pub descriptor: SignedJson,
114    /// The new signed delegation; omitted (or `null`) when unchanged.
115    #[serde(default, skip_serializing_if = "Option::is_none")]
116    pub delegation: Option<SignedJson>,
117    /// The icon bytes, when the descriptor's icon hash changed.
118    #[serde(
119        default,
120        skip_serializing_if = "Option::is_none",
121        with = "check::opt_bytes"
122    )]
123    pub icon: Option<Vec<u8>>,
124}
125
126/// `community.descriptor.publish` response.
127#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
128pub struct Published {
129    /// The accepted revision.
130    pub revision: u64,
131}
132
133/// `community.leave` (`{}`). The owner cannot leave (engine: `CONFLICT`).
134#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
135pub struct Leave {}