Debian Codegraph @

mtxclient/include/mtx/events/policy_rules.hpp

raw symbols SCIP
1 #pragma once
2
3 /// @file
4 /// @brief policy rules for room moderation
5 ///
6 /// With Matrix being an open network where anyone can participate, a very wide range of content
7 /// exists and it is important that users are empowered to select which content they wish to see,
8 /// and which content they wish to block. By extension, room moderators and server admins should
9 /// also be able to select which content they do not wish to host in their rooms and servers.
10 ///
11 /// The protocol’s position on this is one of neutrality: it should not be deciding what content is
12 /// undesirable for any particular entity and should instead be empowering those entities to make
13 /// their own decisions. As such, a generic framework for communicating “moderation policy lists” or
14 /// “moderation policy rooms” is described. Note that this module only describes the data structures
15 /// and not how they should be interpreting: the entity making the decisions on filtering is best
16 /// positioned to interpret the rules how it sees fit.
17 ///
18 /// Moderation policy lists are stored as room state events. There are no restrictions on how the
19 /// rooms can be configured (they could be public, private, encrypted, etc).
20 ///
21 /// There are currently 3 kinds of entities which can be affected by rules: user, server, and room.
22 /// All 3 are described with m.policy.rule.<kind> state events. The state_key for a policy rule is
23 /// an arbitrary string decided by the sender of the rule.
24 ///
25 /// Rules contain recommendations and reasons for the rule existing. The reason is a human-readable
26 /// string which describes the recommendation. Currently only one recommendation, m.ban, is
27 /// specified.
28
29 #include <string_view>
30
31 #if __has_include(<nlohmann/json_fwd.hpp>)
32 #include <nlohmann/json_fwd.hpp>
33 #else
34 #include <nlohmann/json.hpp>
35 #endif
36
37 namespace mtx {
38 namespace events {
39 namespace state {
40 namespace policy_rule {
41
42 //! A recommendation of how to handle the entity.
43 namespace recommendation {
44 /// @brief a recommendation to ban an entity
45 ///
46 /// When this recommendation is used, the entities affected by the rule should be banned from
47 /// participation where possible. The enforcement of this is deliberately left as an implementation
48 /// detail to avoid the protocol imposing its opinion on how the policy list is to be interpreted.
49 inline constexpr std::string_view ban = "m.ban";
50 }
51
52 //! Content of the `m.policy.rule.*` events.
53 //
54 //! The entity described by the state events can contain * and ? to match zero or more and one or
55 //! more characters respectively. Note that rules against rooms can describe a room ID or room alias
56 //! - the subscriber is responsible for resolving the alias to a room ID if desired.
57 struct Rule
58 {
59 //! Required: The entity affected by this rule. Glob characters * and ? can be used to match
60 //! zero or more and one or more characters respectively.
61 std::string entity;
62
63 //! Required: The human-readable description for the recommendation.
64 std::string reason;
65
66 //! Required: The suggested action to take. Currently only m.ban is specified.
67 std::string recommendation;
68
69 friend void from_json(const nlohmann::json &obj, Rule &create);
70 friend void to_json(nlohmann::json &obj, const Rule &create);
71 };
72
73 struct UserRule : public Rule
74 {
75 friend void from_json(const nlohmann::json &obj, UserRule &create);
76 friend void to_json(nlohmann::json &obj, const UserRule &create);
77 };
78 struct RoomRule : public Rule
79 {
80 friend void from_json(const nlohmann::json &obj, RoomRule &create);
81 friend void to_json(nlohmann::json &obj, const RoomRule &create);
82 };
83 struct ServerRule : public Rule
84 {
85 friend void from_json(const nlohmann::json &obj, ServerRule &create);
86 friend void to_json(nlohmann::json &obj, const ServerRule &create);
87 };
88 } // namespace policy_rule
89 } // namespace state
90 } // namespace events
91 } // namespace mtx