ruma_events/policy/
rule.rs1use ruma_common::serde::StringEnum;
4use serde::{Deserialize, Serialize};
5
6use crate::PrivOwnedStr;
7
8pub mod room;
9pub mod server;
10pub mod user;
11
12#[derive(Clone, Debug, Deserialize, Serialize)]
14#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
15pub struct PolicyRuleEventContent {
16 pub entity: String,
21
22 pub recommendation: Recommendation,
24
25 pub reason: String,
27}
28
29impl PolicyRuleEventContent {
30 pub fn new(entity: String, recommendation: Recommendation, reason: String) -> Self {
32 Self { entity, recommendation, reason }
33 }
34}
35
36#[derive(Clone, Debug, Deserialize, Serialize)]
40#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
41pub struct PossiblyRedactedPolicyRuleEventContent {
42 #[serde(skip_serializing_if = "Option::is_none")]
47 pub entity: Option<String>,
48
49 #[serde(skip_serializing_if = "Option::is_none")]
51 pub recommendation: Option<Recommendation>,
52
53 #[serde(skip_serializing_if = "Option::is_none")]
55 pub reason: Option<String>,
56}
57
58impl PossiblyRedactedPolicyRuleEventContent {
59 pub fn new(entity: String, recommendation: Recommendation, reason: String) -> Self {
62 Self { entity: Some(entity), recommendation: Some(recommendation), reason: Some(reason) }
63 }
64
65 pub(crate) fn empty() -> Self {
67 Self { entity: None, recommendation: None, reason: None }
68 }
69}
70
71impl From<PolicyRuleEventContent> for PossiblyRedactedPolicyRuleEventContent {
72 fn from(value: PolicyRuleEventContent) -> Self {
73 let PolicyRuleEventContent { entity, recommendation, reason } = value;
74 Self { entity: Some(entity), recommendation: Some(recommendation), reason: Some(reason) }
75 }
76}
77
78#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
80#[derive(Clone, StringEnum)]
81#[non_exhaustive]
82pub enum Recommendation {
83 #[ruma_enum(rename = "m.ban")]
85 Ban,
86
87 #[doc(hidden)]
88 _Custom(PrivOwnedStr),
89}