Skip to main content

zaun_community_protocol/event/body/
structure.rs

1//! Member-stream structure events (§9.2, §9.3).
2
3use serde::{Deserialize, Serialize};
4
5use crate::command::object::{Channel, ChannelPosition, RolePosition};
6use crate::ids::{ChannelId, RoleId};
7use crate::json::SignedJson;
8
9/// `community.descriptor_updated`: signed `descriptor` and `delegation`.
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11pub struct DescriptorUpdated {
12    /// The new signed descriptor; verify before use.
13    pub descriptor: SignedJson,
14    /// The signed delegation it references.
15    pub delegation: SignedJson,
16}
17
18/// `channel.created`: the channel object plus `reason?: "access_gained"` (§9.3).
19#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
20pub struct ChannelCreated {
21    /// The channel.
22    #[serde(flatten)]
23    pub channel: Channel,
24    /// Set when the channel became visible rather than created.
25    #[serde(default, skip_serializing_if = "Option::is_none")]
26    pub reason: Option<VisibilityReason>,
27}
28
29/// `channel.deleted`: `{channel_id, reason?: "access_lost"}` (§9.3).
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
31pub struct ChannelDeleted {
32    /// The channel.
33    pub channel_id: ChannelId,
34    /// Set when the channel became invisible rather than deleted.
35    #[serde(default, skip_serializing_if = "Option::is_none")]
36    pub reason: Option<VisibilityReason>,
37}
38
39/// A visibility change (§9.3). SPEC: a plain string (`"access_gained"`), as written.
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
41#[serde(rename_all = "snake_case")]
42pub enum VisibilityReason {
43    /// The member can now view the channel.
44    AccessGained,
45    /// The member can no longer view the channel.
46    AccessLost,
47}
48
49/// `channel.reordered`: `positions` (only channels the member can see).
50///
51/// SPEC: the entry shape is not given; the `channel.reorder` entry is reused.
52#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
53pub struct ChannelsReordered {
54    /// New positions and parents.
55    pub positions: Vec<ChannelPosition>,
56}
57
58/// `role.deleted`: `{role_id}`.
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
60pub struct RoleDeleted {
61    /// The role.
62    pub role_id: RoleId,
63}
64
65/// `role.reordered`: `positions`. SPEC: the `role.reorder` entry is reused.
66#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
67pub struct RolesReordered {
68    /// New positions.
69    pub positions: Vec<RolePosition>,
70}