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//! \brief The content of a join rule event
22//!
23//! \sa https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
27};
28} // namespace EventContent
29
30constexpr inline auto JoinRuleKey = "join_rule"_L1;
31constexpr inline auto AllowKey = "allow"_L1;
32
33template<>
34inline EventContent::AllowCondition fromJson(const QJsonObject& jo)
35{
36 return EventContent::AllowCondition {
37 fromJson<QString>(jo[RoomIdKey]),
38 fromJson<QString>(jo[TypeKey])
39 };
40}
41
42template<>
43inline auto toJson(const EventContent::AllowCondition& c)
44{
45 QJsonObject jo;
46 addParam<IfNotEmpty>(jo, RoomIdKey, c.roomId);
47 addParam<IfNotEmpty>(jo, TypeKey, c.type);
48 return jo;
49}
50
51template<>
52inline EventContent::JoinRuleContent fromJson(const QJsonObject& jo)
53{
54 return EventContent::JoinRuleContent{fromJson<JoinRule>(jo[JoinRuleKey]),
55 fromJson<QList<EventContent::AllowCondition>>(
56 jo[AllowKey])};
57}
58
59template<>
60inline auto toJson(const EventContent::JoinRuleContent& c)
61{
62 QJsonObject jo;
63 addParam<IfNotEmpty>(jo, JoinRuleKey, c.joinRule);
64 addParam<IfNotEmpty>(jo, AllowKey, c.allow);
65 return jo;
66}
67
68//! \brief Class to define a join rule state event.
69//!
70//! \sa Quotient::StateEvent, https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
72 : public KeylessStateEventBase<JoinRulesEvent, EventContent::JoinRuleContent>
73{
74public:
75 QUO_EVENT(JoinRulesEvent, "m.room.join_rules")
76 using KeylessStateEventBase::KeylessStateEventBase;
77
78 //! \brief The join rule for the room.
79 //!
80 //! \sa https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
81 JoinRule joinRule() const { return content().joinRule; }
82
83 //! \brief The allow rules for restricted rooms.
84 //!
85 //! \sa https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
86 QList<EventContent::AllowCondition> allow() const { return content().allow; }
87};
88} // namespace Quotient
Class to define a join rule state event.
#define QUO_EVENT(CppType_, MatrixType_)
Supply event metatype information in (specific) event types.
Definition event.h:428
constexpr auto AllowKey
auto toJson(const EventContent::AllowCondition &c)
constexpr auto JoinRuleKey
EventContent::AllowCondition fromJson(const QJsonObject &jo)
#define QUOTIENT_API
Definition of an allow AllowCondition.
The content of a join rule event.