Skip to main content

zaun_community_protocol/command/object/
report.rs

1//! Member reports (specification §8.10, governance §12, schema.md `reports`).
2//!
3//! One canonical set: categories `spam`, `harassment`, `illegal`, `exploitation`, `rules`,
4//! `other`; statuses `open`, `reviewing`, `resolved`; a resolution's outcome is
5//! `action_taken`, `no_action`, `duplicate` or `invalid` (a dismissed report is `resolved`
6//! with `no_action` or `invalid`).
7
8use serde::{Deserialize, Serialize};
9
10use super::Embed;
11use crate::ids::{ChannelId, MemberId, MessageId, ReportId};
12
13/// A report (§8.10). Only for `MANAGE_REPORTS` holders and, without other reporters' data,
14/// the reporter.
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct Report {
17    /// Host-assigned id.
18    pub report_id: ReportId,
19    /// The category.
20    pub category: ReportCategory,
21    /// ≤ 2 000 scalars.
22    #[serde(default, skip_serializing_if = "Option::is_none")]
23    pub description: Option<String>,
24    /// The reported member or message.
25    pub target: ReportTarget,
26    /// Host snapshots of the selected messages.
27    pub evidence: Vec<Evidence>,
28    /// Some snapshots were left out to keep the report within a frame (items with
29    /// `omitted: true`): `report.get` with `evidence_from` set to this index returns them.
30    #[serde(default, skip_serializing_if = "Option::is_none")]
31    pub evidence_next: Option<u32>,
32    /// The reporter.
33    pub reporter_id: MemberId,
34    /// Workflow status.
35    pub status: ReportStatus,
36    /// Set once resolved.
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub resolution: Option<Resolution>,
39    /// Creation time, ms.
40    pub created_at: u64,
41}
42
43/// `category` (§8.10).
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
45#[serde(tag = "t", content = "c", rename_all = "snake_case")]
46pub enum ReportCategory {
47    /// Spam.
48    Spam,
49    /// Harassment.
50    Harassment,
51    /// Illegal content.
52    Illegal,
53    /// Exploitation.
54    Exploitation,
55    /// Community rules.
56    Rules,
57    /// Anything else.
58    Other,
59}
60
61/// `target: {t: "member"|"message", c}` (§8.10).
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
63#[serde(tag = "t", content = "c", rename_all = "snake_case")]
64pub enum ReportTarget {
65    /// A member.
66    Member(MemberId),
67    /// A message.
68    Message(MessageId),
69}
70
71/// One evidence item (§8.10).
72#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
73pub struct Evidence {
74    /// The message's channel.
75    pub channel_id: ChannelId,
76    /// The message.
77    pub message_id: MessageId,
78    /// The host's snapshot at report time (`content_snapshot?`, §8.10); absent when redacted.
79    #[serde(default, skip_serializing_if = "Option::is_none")]
80    pub content_snapshot: Option<String>,
81    /// The message's embeds at report time; absent when it had none or when redacted.
82    #[serde(default, skip_serializing_if = "Vec::is_empty")]
83    pub embeds_snapshot: Vec<Embed>,
84    /// The snapshot was left out of this response for size; `report.get` with
85    /// `evidence_from` returns it (see [`Report::evidence_next`]).
86    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
87    pub omitted: bool,
88    /// Withheld from this viewer (permissions §4.6).
89    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
90    pub redacted: bool,
91}
92
93/// `status` (§8.10): a plain string (§7.5), exactly `"open"|"reviewing"|"resolved"`.
94#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
95#[serde(rename_all = "snake_case")]
96pub enum ReportStatus {
97    /// New.
98    Open,
99    /// A moderator is reviewing it.
100    Reviewing,
101    /// Resolved.
102    Resolved,
103}
104
105/// `resolution: {outcome, note?, actor_id, at}` (§8.10).
106#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
107pub struct Resolution {
108    /// The outcome.
109    pub outcome: Outcome,
110    /// The moderator's note.
111    #[serde(default, skip_serializing_if = "Option::is_none")]
112    pub note: Option<String>,
113    /// The resolving moderator.
114    pub actor_id: MemberId,
115    /// Resolution time, ms.
116    pub at: u64,
117}
118
119/// `outcome` (§8.10).
120#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
121#[serde(tag = "t", content = "c", rename_all = "snake_case")]
122pub enum Outcome {
123    /// A moderation action was taken separately.
124    ActionTaken,
125    /// No action.
126    NoAction,
127    /// Duplicate of another report.
128    Duplicate,
129    /// Not a valid report.
130    Invalid,
131}