diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 562b452bd..2b17e9057 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -107,8 +107,6 @@ add_library(neochat STATIC models/imagepacksmodel.h events/imagepackevent.cpp events/imagepackevent.h - events/joinrulesevent.cpp - events/joinrulesevent.h models/reactionmodel.cpp models/reactionmodel.h delegatesizehelper.cpp diff --git a/src/events/joinrulesevent.cpp b/src/events/joinrulesevent.cpp deleted file mode 100644 index a239f69f0..000000000 --- a/src/events/joinrulesevent.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-FileCopyrightText: 2019 Kitsune Ral -// SPDX-License-Identifier: LGPL-2.1-or-later - -#include "joinrulesevent.h" - -using namespace Quotient; - -QString JoinRulesEvent::joinRule() const -{ - return fromJson(contentJson()["join_rule"_L1]); -} - -QJsonArray JoinRulesEvent::allow() const -{ - return contentJson()["allow"_L1].toArray(); -} diff --git a/src/events/joinrulesevent.h b/src/events/joinrulesevent.h deleted file mode 100644 index 1ebafbe02..000000000 --- a/src/events/joinrulesevent.h +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-FileCopyrightText: 2021 Carl Schwan -// SPDX-License-Identifier: LGPL-2.1-or-later - -#pragma once - -#include - -namespace Quotient -{ -/** - * @class JoinRulesEvent - * - * Class to define a join rule state event. - * - * @sa Quotient::StateEvent - */ -class JoinRulesEvent : public StateEvent -{ -public: - QUO_EVENT(JoinRulesEvent, "m.room.join_rules") - - explicit JoinRulesEvent(const QJsonObject &obj) - : StateEvent(obj) - { - } - - /** - * @brief The join rule for the room. - * - * see https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules for - * the available join rules for a room. - */ - QString joinRule() const; - - /** - * @brief The allow rule for restricted rooms. - * - * see https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules for - * full details on allow rules. - */ - QJsonArray allow() const; -}; -} diff --git a/src/main.cpp b/src/main.cpp index bedf926d8..d40e16f94 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -239,6 +239,7 @@ int main(int argc, char *argv[]) Q_IMPORT_QML_PLUGIN(org_kde_neochat_chatbarPlugin) qml_register_types_org_kde_neochat(); + qmlRegisterUncreatableMetaObject(Quotient::staticMetaObject, "Quotient", 1, 0, "JoinRule", u"Access to JoinRule enum only"_s); QQmlApplicationEngine engine; diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 1c64f9e70..030c14e99 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -40,7 +40,6 @@ #include "chatbarcache.h" #include "clipboard.h" #include "eventhandler.h" -#include "events/joinrulesevent.h" #include "events/pollevent.h" #include "filetransferpseudojob.h" #include "neochatconfig.h" @@ -133,7 +132,6 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS Q_EMIT canEncryptRoomChanged(); Q_EMIT parentIdsChanged(); Q_EMIT canonicalParentChanged(); - Q_EMIT joinRuleChanged(); Q_EMIT readOnlyChanged(); }); connect(connection, &Connection::capabilitiesLoaded, this, &NeoChatRoom::maxRoomVersionChanged); @@ -605,60 +603,6 @@ void NeoChatRoom::deleteMessagesByUser(const QString &user, const QString &reaso doDeleteMessagesByUser(user, reason); } -QString NeoChatRoom::joinRule() const -{ - auto joinRulesEvent = currentState().get(); - if (!joinRulesEvent) { - return {}; - } - return joinRulesEvent->joinRule(); -} - -void NeoChatRoom::setJoinRule(const QString &joinRule, const QList &allowedSpaces) -{ - if (!canSendState("m.room.join_rules"_L1)) { - qWarning() << "Power level too low to set join rules"; - return; - } - auto actualRule = joinRule; - if (joinRule == "restricted"_L1 && allowedSpaces.isEmpty()) { - actualRule = "private"_L1; - } - - QJsonArray allowConditions; - if (actualRule == "restricted"_L1) { - for (auto allowedSpace : allowedSpaces) { - allowConditions += QJsonObject{{"type"_L1, "m.room_membership"_L1}, {"room_id"_L1, allowedSpace}}; - } - } - - QJsonObject content; - content.insert("join_rule"_L1, joinRule); - if (!allowConditions.isEmpty()) { - content.insert("allow"_L1, allowConditions); - } - qWarning() << content; - setState("m.room.join_rules"_L1, {}, content); - // Not emitting joinRuleChanged() here, since that would override the change in the UI with the *current* value, which is not the *new* value. -} - -QList NeoChatRoom::restrictedIds() const -{ - auto joinRulesEvent = currentState().get(); - if (!joinRulesEvent) { - return {}; - } - if (joinRulesEvent->joinRule() != "restricted"_L1) { - return {}; - } - - QList roomIds; - for (auto allow : joinRulesEvent->allow()) { - roomIds += allow.toObject().value("room_id"_L1).toString(); - } - return roomIds; -} - QString NeoChatRoom::historyVisibility() const { if (auto stateEvent = currentState().get("m.room.history_visibility"_L1)) { diff --git a/src/neochatroom.h b/src/neochatroom.h index 864448802..803c6eacb 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -134,22 +134,6 @@ class NeoChatRoom : public Quotient::Room */ Q_PROPERTY(bool readOnly READ readOnly NOTIFY readOnlyChanged) - /** - * @brief The current join rule for the room as a QString. - * - * Possible values are [public, knock, invite, private, restricted]. - * - * @sa https://spec.matrix.org/v1.5/client-server-api/#mroomjoin_rules - */ - Q_PROPERTY(QString joinRule READ joinRule WRITE setJoinRule NOTIFY joinRuleChanged) - - /** - * @brief The space IDs that members of can join this room. - * - * Empty if the join rule is not restricted. - */ - Q_PROPERTY(QList restrictedIds READ restrictedIds NOTIFY joinRuleChanged) - /** * @brief Get the maximum room version that the server supports. * @@ -420,25 +404,6 @@ public: bool readOnly() const; - [[nodiscard]] QString joinRule() const; - - /** - * @brief Set the join rule for the room. - * - * Will fail if the user doesn't have the required privileges. - * - * @param joinRule the join rule [public, knock, invite, private, restricted]. - * @param allowedSpaces only used when the join rule is restricted. This is a - * list of space Matrix IDs that members of can join without an invite. - * If the rule is restricted and this list is empty it is treated as a join - * rule of private instead. - * - * @sa https://spec.matrix.org/latest/client-server-api/#mroomjoin_rules - */ - Q_INVOKABLE void setJoinRule(const QString &joinRule, const QList &allowedSpaces = {}); - - QList restrictedIds() const; - int maxRoomVersion() const; /** @@ -693,7 +658,6 @@ Q_SIGNALS: void displayNameChanged(); void pushNotificationStateChanged(PushNotificationState::State state); void canEncryptRoomChanged(); - void joinRuleChanged(); void historyVisibilityChanged(); void defaultUrlPreviewStateChanged(); void urlPreviewEnabledChanged(); diff --git a/src/qml/SelectSpacesDialog.qml b/src/qml/SelectSpacesDialog.qml index 3475eb96d..420c84c35 100644 --- a/src/qml/SelectSpacesDialog.qml +++ b/src/qml/SelectSpacesDialog.qml @@ -9,6 +9,8 @@ import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.formcard as FormCard import org.kde.kirigamiaddons.labs.components as Components +import Quotient + import org.kde.neochat Kirigami.Dialog { @@ -42,7 +44,7 @@ Kirigami.Dialog { ids.push(spaceGroup.buttons[i].modelData.id); } } - root.room.setJoinRule("restricted", ids); + root.room.setJoinRule(JoinRule.Restricted, ids); } QQC2.ButtonGroup { diff --git a/src/settings/RoomSecurityPage.qml b/src/settings/RoomSecurityPage.qml index e7ff68f40..a18c1be34 100644 --- a/src/settings/RoomSecurityPage.qml +++ b/src/settings/RoomSecurityPage.qml @@ -9,6 +9,8 @@ import QtQuick.Layouts import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.formcard as FormCard +import Quotient + import org.kde.neochat FormCard.FormCardPage { @@ -45,23 +47,23 @@ FormCard.FormCardPage { FormCard.FormRadioDelegate { text: i18nc("@option:check", "Private (invite only)") description: i18n("Only invited people can join.") - checked: room.joinRule === "invite" + checked: room.joinRule === JoinRule.Invite enabled: room.canSendState("m.room.join_rules") - onCheckedChanged: if (checked && room.joinRule != "invite") { - root.room.joinRule = "invite"; + onCheckedChanged: if (checked && room.joinRule != JoinRule.Invite) { + root.room.joinRule = JoinRule.Invite; } } FormCard.FormRadioDelegate { text: i18nc("@option:check", "Space members") description: i18n("Anyone in the selected spaces can find and join.") + (!["8", "9", "10"].includes(room.version) ? `\n${needUpgradeRoom}` : "") - checked: room.joinRule === "restricted" + checked: room.joinRule === JoinRule.Restricted enabled: room.canSendState("m.room.join_rules") && ["8", "9", "10"].includes(room.version) - onCheckedChanged: if (checked && room.joinRule != "restricted") { + onCheckedChanged: if (checked && room.joinRule != JoinRule.Restricted) { selectSpacesDialog.createObject(QQC2.Overlay.overlay).open(); } contentItem.children: QQC2.Button { - visible: root.room.joinRule === "restricted" + visible: root.room.joinRule === JoinRule.Restricted text: i18n("Select spaces") icon.name: "list-add" @@ -82,20 +84,20 @@ FormCard.FormCardPage { FormCard.FormRadioDelegate { text: i18nc("@option:check", "Knock") description: i18n("People not in the room need to request an invite to join the room.") + (!["7", "8", "9", "10"].includes(room.version) ? `\n${needUpgradeRoom}` : "") - checked: room.joinRule === "knock" + checked: room.joinRule === JoinRule.Knock // https://spec.matrix.org/v1.4/rooms/#feature-matrix enabled: room.canSendState("m.room.join_rules") && ["7", "8", "9", "10"].includes(room.version) - onCheckedChanged: if (checked && room.joinRule != "knock") { - root.room.joinRule = "knock"; + onCheckedChanged: if (checked && room.joinRule != JoinRule.Knock) { + root.room.joinRule = JoinRule.Knock; } } FormCard.FormRadioDelegate { text: i18nc("@option:check", "Public") description: i18nc("@option:check", "Anyone can find and join.") - checked: room.joinRule === "public" + checked: room.joinRule === JoinRule.Public enabled: room.canSendState("m.room.join_rules") - onCheckedChanged: if (checked && root.room.joinRule != "public") { - root.room.joinRule = "public"; + onCheckedChanged: if (checked && root.room.joinRule != JoinRule.Public) { + root.room.joinRule = JoinRule.Public; } } }