Skip to content

Commit

Permalink
Move JoinRule to quotient common
Browse files Browse the repository at this point in the history
  • Loading branch information
nvrWhere committed Feb 9, 2025
1 parent 77de0ec commit 9a4252f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
21 changes: 5 additions & 16 deletions Quotient/events/roomjoinrulesevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

#pragma once

#include <Quotient/events/stateevent.h>
#include <Quotient/quotient_common.h>
#include "stateevent.h"

namespace Quotient
{
namespace EventContent {
Q_NAMESPACE_EXPORT(QUOTIENT_API)

//! \brief Definition of an allow AllowCondition
//!
Expand All @@ -18,17 +18,6 @@ struct AllowCondition {
QString type;
};

//! Enum representing the available room join rules
enum JoinRule {
Public,
Knock,
Invite,
Private,
Restricted,
KnockRestricted,
};
Q_ENUM_NS(JoinRule)

[[maybe_unused]] constexpr std::array JoinRuleStrings {
"public"_L1,
"knock"_L1,
Expand Down Expand Up @@ -69,7 +58,7 @@ template<>
inline EventContent::JoinRuleContent fromJson(const QJsonObject& jo)
{
return EventContent::JoinRuleContent {
enumFromJsonString<EventContent::JoinRule>(jo["join_rule"_L1].toString(), EventContent::JoinRuleStrings).value_or(EventContent::Public),
enumFromJsonString<JoinRule>(jo["join_rule"_L1].toString(), EventContent::JoinRuleStrings).value_or(Public),
fromJson<QList<EventContent::AllowCondition>>(jo["allow"_L1])
};
}
Expand All @@ -78,7 +67,7 @@ template<>
inline auto toJson(const EventContent::JoinRuleContent& c)
{
QJsonObject jo;
addParam<IfNotEmpty>(jo, "join_rule"_L1, enumToJsonString<EventContent::JoinRule>(c.joinRule, EventContent::JoinRuleStrings));
addParam<IfNotEmpty>(jo, "join_rule"_L1, enumToJsonString<JoinRule>(c.joinRule, EventContent::JoinRuleStrings));
addParam<IfNotEmpty>(jo, "allow"_L1, c.allow);
return jo;
}
Expand All @@ -96,7 +85,7 @@ class JoinRulesEvent : public KeylessStateEventBase<JoinRulesEvent,
//! \brief The join rule for the room.
//!
//! \sa https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
EventContent::JoinRule joinRule() const { return content().joinRule; }
JoinRule joinRule() const { return content().joinRule; }

//! \brief The allow rules for restricted rooms.
//!
Expand Down
11 changes: 11 additions & 0 deletions Quotient/quotient_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ enum class EncryptionType : uint8_t {
};
Q_ENUM_NS(EncryptionType)

//! Enum representing the available room join rules
enum JoinRule {
Public,
Knock,
Invite,
Private,
Restricted,
KnockRestricted,
};
Q_ENUM_NS(JoinRule)

} // namespace Quotient
Q_DECLARE_OPERATORS_FOR_FLAGS(Quotient::MembershipMask)
Q_DECLARE_OPERATORS_FOR_FLAGS(Quotient::JoinStates)
8 changes: 4 additions & 4 deletions Quotient/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1535,9 +1535,9 @@ RoomStateView Room::currentState() const
return d->currentState;
}

EventContent::JoinRule Room::joinRule() const
JoinRule Room::joinRule() const
{
return currentState().queryOr(&JoinRulesEvent::joinRule, EventContent::Public);
return currentState().queryOr(&JoinRulesEvent::joinRule, Public);
}

QList<QString> Room::allowIds() const
Expand All @@ -1549,13 +1549,13 @@ QList<QString> Room::allowIds() const
return allowIds;
}

void Room::setJoinRule(EventContent::JoinRule newRule, const QList<QString>& allowedRooms)
void Room::setJoinRule(JoinRule newRule, const QList<QString>& allowedRooms)
{
if (memberEffectivePowerLevel() < powerLevelFor<JoinRulesEvent>()) {
return;
}

EventContent::JoinRule actualRule = (newRule == EventContent::Restricted || newRule == EventContent::KnockRestricted) && allowedRooms.isEmpty() ? EventContent::Invite : newRule;
JoinRule actualRule = (newRule == Restricted || newRule == KnockRestricted) && allowedRooms.isEmpty() ? Invite : newRule;
QList<EventContent::AllowCondition> newAllow;
for (const auto& room :allowedRooms) {
newAllow.append({room, "m.room_membership"_L1});
Expand Down
6 changes: 3 additions & 3 deletions Quotient/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class QUOTIENT_API Room : public QObject {
Q_PROPERTY(QStringList tagNames READ tagNames NOTIFY tagsChanged)
Q_PROPERTY(bool isFavourite READ isFavourite NOTIFY tagsChanged STORED false)
Q_PROPERTY(bool isLowPriority READ isLowPriority NOTIFY tagsChanged STORED false)
Q_PROPERTY(EventContent::JoinRule joinRule READ joinRule WRITE setJoinRule NOTIFY joinRuleChanged)
Q_PROPERTY(JoinRule joinRule READ joinRule WRITE setJoinRule NOTIFY joinRuleChanged)
Q_PROPERTY(QList<QString> allowIds READ allowIds NOTIFY joinRuleChanged)

Q_PROPERTY(GetRoomEventsJob* eventsHistoryJob READ eventsHistoryJob NOTIFY eventsHistoryJobChanged)
Expand Down Expand Up @@ -678,7 +678,7 @@ class QUOTIENT_API Room : public QObject {
//! \brief The current Join Rule for the room
//!
//! \sa https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
EventContent::JoinRule joinRule() const;
JoinRule joinRule() const;

//! \brief Set the Join Rule for the room
//!
Expand All @@ -694,7 +694,7 @@ class QUOTIENT_API Room : public QObject {
//! input. I.e. only memebers of space `x` can join this room.
//!
//! \sa https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules
Q_INVOKABLE void setJoinRule(EventContent::JoinRule newRule, const QList<QString>& allowedRooms = {});
Q_INVOKABLE void setJoinRule(JoinRule newRule, const QList<QString>& allowedRooms = {});

//! \brief The list of Room IDs for when the join rule is Restricted
//!
Expand Down

0 comments on commit 9a4252f

Please sign in to comment.