libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
roomjoinrulesevent.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 James Graham <james.h.graham@protonmail.com>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include "../quotient_common.h"
7#include "stateevent.h"
8
9namespace Quotient
10{
11namespace EventContent {
12
13//! \brief Definition of an allow AllowCondition
14//!
15//! \sa https://spec.matrix.org/latest/client-server-api/#mroomjoin_ruless
19};
20
21[[maybe_unused]] constexpr std::array JoinRuleStrings {
22 "public"_L1,
23 "knock"_L1,
24 "invite"_L1,
25 "private"_L1,
26 "restricted"_L1,
27 "knock_restricted"_L1,
28};
29
30//! \brief The content of a join rule event
31//!
32//! \sa https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
36};
37} // namespace EventContent
38
39template<>
40inline EventContent::AllowCondition fromJson(const QJsonObject& jo)
41{
42 return EventContent::AllowCondition {
43 fromJson<QString>(jo["room_id"_L1]),
44 fromJson<QString>(jo["type"_L1])
45 };
46}
47
48template<>
49inline auto toJson(const EventContent::AllowCondition& c)
50{
51 QJsonObject jo;
52 addParam<IfNotEmpty>(jo, "room_id"_L1, c.roomId);
53 addParam<IfNotEmpty>(jo, "type"_L1, c.type);
54 return jo;
55}
56
57template<>
58inline EventContent::JoinRuleContent fromJson(const QJsonObject& jo)
59{
60 return EventContent::JoinRuleContent {
61 enumFromJsonString<JoinRule>(jo["join_rule"_L1].toString(), EventContent::JoinRuleStrings).value_or(Public),
62 fromJson<QList<EventContent::AllowCondition>>(jo["allow"_L1])
63 };
64}
65
66template<>
67inline auto toJson(const EventContent::JoinRuleContent& c)
68{
69 QJsonObject jo;
70 addParam<IfNotEmpty>(jo, "join_rule"_L1, enumToJsonString<JoinRule>(c.joinRule, EventContent::JoinRuleStrings));
71 addParam<IfNotEmpty>(jo, "allow"_L1, c.allow);
72 return jo;
73}
74
75//! \brief Class to define a join rule state event.
76//!
77//! \sa Quotient::StateEvent, https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
80{
81public:
82 QUO_EVENT(JoinRulesEvent, "m.room.join_rules")
84
85 //! \brief The join rule for the room.
86 //!
87 //! \sa https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
88 JoinRule joinRule() const { return content().joinRule; }
89
90 //! \brief The allow rules for restricted rooms.
91 //!
92 //! \sa https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
93 QList<EventContent::AllowCondition> allow() const { return content().allow; }
94};
95} // namespace Quotient
Class to define a join rule state event.
QList< EventContent::AllowCondition > allow() const
The allow rules for restricted rooms.
JoinRule joinRule() const
The join rule for the room.
#define QUO_EVENT(CppType_, MatrixType_)
Supply event metatype information in (specific) event types.
Definition event.h:436
constexpr std::array JoinRuleStrings
auto toJson(const EventContent::AllowCondition &c)
bool fromJson(const QJsonValue &jv)
Definition converters.h:231
JoinRule
Enum representing the available room join rules.
auto toJson(const EventContent::JoinRuleContent &c)
Definition of an allow AllowCondition.
The content of a join rule event.