zaun_community_protocol/command/object/lockdown.rs
1//! Emergency lockdown (specification §8.10, governance §9).
2
3use serde::{Deserialize, Serialize};
4
5use crate::ids::{LockdownId, MemberId};
6
7/// The full lockdown record (§8.10), for `MANAGE_SAFETY` holders: `{ lockdown_id,
8/// restrictions, forced_slowmode_s?, newcomer_window_s?, expires_at, reason?, actor_id }`.
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10pub struct Lockdown {
11 /// Host-assigned id.
12 pub lockdown_id: LockdownId,
13 /// Active restrictions (≥ 1).
14 pub restrictions: Vec<Restriction>,
15 /// Forced minimum slowmode on every channel, s.
16 #[serde(default, skip_serializing_if = "Option::is_none")]
17 pub forced_slowmode_s: Option<u32>,
18 /// Window for `restrict_newcomers`, s; present only with that restriction.
19 #[serde(default, skip_serializing_if = "Option::is_none")]
20 pub newcomer_window_s: Option<u64>,
21 /// Expiry, ms.
22 pub expires_at: u64,
23 /// The moderator's reason.
24 #[serde(default, skip_serializing_if = "Option::is_none")]
25 pub reason: Option<String>,
26 /// The enabling moderator.
27 pub actor_id: MemberId,
28}
29
30/// The public form (§8.10), for members without `MANAGE_SAFETY`: `{active,
31/// restrictions_affecting_you, expires_at}`. With no active lockdown (disabled or expired) it
32/// is `{active: false, restrictions_affecting_you: [], expires_at: null}`, sent to every
33/// member by `moderation.lockdown.updated`.
34#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
35pub struct LockdownPublic {
36 /// Whether a lockdown is active.
37 pub active: bool,
38 /// The restrictions that apply to the viewer.
39 pub restrictions_affecting_you: Vec<Restriction>,
40 /// Expiry, ms; `null` when inactive.
41 pub expires_at: Option<u64>,
42}
43
44/// A lockdown as the viewer may see it. The full form is tried first. On disable or expiry,
45/// `moderation.lockdown.updated` carries the inactive public form to every member,
46/// `MANAGE_SAFETY` holders included (§8.10).
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum LockdownView {
50 /// For `MANAGE_SAFETY` holders.
51 Full(Lockdown),
52 /// For everyone else.
53 Public(LockdownPublic),
54}
55
56/// One lockdown restriction (§8.10).
57#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
58#[serde(tag = "t", content = "c", rename_all = "snake_case")]
59pub enum Restriction {
60 /// No new memberships.
61 PauseJoins,
62 /// `invite.redeem` refused.
63 DisableInviteRedeem,
64 /// `invite.create` refused.
65 DisableInviteCreate,
66 /// Every join starts `pending`.
67 RequireApproval,
68 /// The newcomer mask applies to members admitted within `newcomer_window_s`.
69 RestrictNewcomers,
70 /// No attachments.
71 DisableAttachments,
72 /// No links in content.
73 DisableLinks,
74 /// No mass mentions.
75 DisableMassMentions,
76 /// No voice.
77 RestrictVoice,
78 /// Expensive operations blocked.
79 RestrictExpensive,
80}