Move to upstream JoinRuleEvent
This commit is contained in:
@@ -107,8 +107,6 @@ add_library(neochat STATIC
|
|||||||
models/imagepacksmodel.h
|
models/imagepacksmodel.h
|
||||||
events/imagepackevent.cpp
|
events/imagepackevent.cpp
|
||||||
events/imagepackevent.h
|
events/imagepackevent.h
|
||||||
events/joinrulesevent.cpp
|
|
||||||
events/joinrulesevent.h
|
|
||||||
models/reactionmodel.cpp
|
models/reactionmodel.cpp
|
||||||
models/reactionmodel.h
|
models/reactionmodel.h
|
||||||
delegatesizehelper.cpp
|
delegatesizehelper.cpp
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2019 Kitsune Ral <Kitsune-Ral@users.sf.net>
|
|
||||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
||||||
|
|
||||||
#include "joinrulesevent.h"
|
|
||||||
|
|
||||||
using namespace Quotient;
|
|
||||||
|
|
||||||
QString JoinRulesEvent::joinRule() const
|
|
||||||
{
|
|
||||||
return fromJson<QString>(contentJson()["join_rule"_L1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonArray JoinRulesEvent::allow() const
|
|
||||||
{
|
|
||||||
return contentJson()["allow"_L1].toArray();
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
|
|
||||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Quotient/events/stateevent.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -239,6 +239,7 @@ int main(int argc, char *argv[])
|
|||||||
Q_IMPORT_QML_PLUGIN(org_kde_neochat_chatbarPlugin)
|
Q_IMPORT_QML_PLUGIN(org_kde_neochat_chatbarPlugin)
|
||||||
|
|
||||||
qml_register_types_org_kde_neochat();
|
qml_register_types_org_kde_neochat();
|
||||||
|
qmlRegisterUncreatableMetaObject(Quotient::staticMetaObject, "Quotient", 1, 0, "JoinRule", u"Access to JoinRule enum only"_s);
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,6 @@
|
|||||||
#include "chatbarcache.h"
|
#include "chatbarcache.h"
|
||||||
#include "clipboard.h"
|
#include "clipboard.h"
|
||||||
#include "eventhandler.h"
|
#include "eventhandler.h"
|
||||||
#include "events/joinrulesevent.h"
|
|
||||||
#include "events/pollevent.h"
|
#include "events/pollevent.h"
|
||||||
#include "filetransferpseudojob.h"
|
#include "filetransferpseudojob.h"
|
||||||
#include "neochatconfig.h"
|
#include "neochatconfig.h"
|
||||||
@@ -133,7 +132,6 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
|
|||||||
Q_EMIT canEncryptRoomChanged();
|
Q_EMIT canEncryptRoomChanged();
|
||||||
Q_EMIT parentIdsChanged();
|
Q_EMIT parentIdsChanged();
|
||||||
Q_EMIT canonicalParentChanged();
|
Q_EMIT canonicalParentChanged();
|
||||||
Q_EMIT joinRuleChanged();
|
|
||||||
Q_EMIT readOnlyChanged();
|
Q_EMIT readOnlyChanged();
|
||||||
});
|
});
|
||||||
connect(connection, &Connection::capabilitiesLoaded, this, &NeoChatRoom::maxRoomVersionChanged);
|
connect(connection, &Connection::capabilitiesLoaded, this, &NeoChatRoom::maxRoomVersionChanged);
|
||||||
@@ -605,60 +603,6 @@ void NeoChatRoom::deleteMessagesByUser(const QString &user, const QString &reaso
|
|||||||
doDeleteMessagesByUser(user, reason);
|
doDeleteMessagesByUser(user, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString NeoChatRoom::joinRule() const
|
|
||||||
{
|
|
||||||
auto joinRulesEvent = currentState().get<JoinRulesEvent>();
|
|
||||||
if (!joinRulesEvent) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
return joinRulesEvent->joinRule();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NeoChatRoom::setJoinRule(const QString &joinRule, const QList<QString> &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<QString> NeoChatRoom::restrictedIds() const
|
|
||||||
{
|
|
||||||
auto joinRulesEvent = currentState().get<JoinRulesEvent>();
|
|
||||||
if (!joinRulesEvent) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
if (joinRulesEvent->joinRule() != "restricted"_L1) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<QString> roomIds;
|
|
||||||
for (auto allow : joinRulesEvent->allow()) {
|
|
||||||
roomIds += allow.toObject().value("room_id"_L1).toString();
|
|
||||||
}
|
|
||||||
return roomIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString NeoChatRoom::historyVisibility() const
|
QString NeoChatRoom::historyVisibility() const
|
||||||
{
|
{
|
||||||
if (auto stateEvent = currentState().get("m.room.history_visibility"_L1)) {
|
if (auto stateEvent = currentState().get("m.room.history_visibility"_L1)) {
|
||||||
|
|||||||
@@ -134,22 +134,6 @@ class NeoChatRoom : public Quotient::Room
|
|||||||
*/
|
*/
|
||||||
Q_PROPERTY(bool readOnly READ readOnly NOTIFY readOnlyChanged)
|
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<QString> restrictedIds READ restrictedIds NOTIFY joinRuleChanged)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the maximum room version that the server supports.
|
* @brief Get the maximum room version that the server supports.
|
||||||
*
|
*
|
||||||
@@ -420,25 +404,6 @@ public:
|
|||||||
|
|
||||||
bool readOnly() const;
|
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<QString> &allowedSpaces = {});
|
|
||||||
|
|
||||||
QList<QString> restrictedIds() const;
|
|
||||||
|
|
||||||
int maxRoomVersion() const;
|
int maxRoomVersion() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -693,7 +658,6 @@ Q_SIGNALS:
|
|||||||
void displayNameChanged();
|
void displayNameChanged();
|
||||||
void pushNotificationStateChanged(PushNotificationState::State state);
|
void pushNotificationStateChanged(PushNotificationState::State state);
|
||||||
void canEncryptRoomChanged();
|
void canEncryptRoomChanged();
|
||||||
void joinRuleChanged();
|
|
||||||
void historyVisibilityChanged();
|
void historyVisibilityChanged();
|
||||||
void defaultUrlPreviewStateChanged();
|
void defaultUrlPreviewStateChanged();
|
||||||
void urlPreviewEnabledChanged();
|
void urlPreviewEnabledChanged();
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import org.kde.kirigami as Kirigami
|
|||||||
import org.kde.kirigamiaddons.formcard as FormCard
|
import org.kde.kirigamiaddons.formcard as FormCard
|
||||||
import org.kde.kirigamiaddons.labs.components as Components
|
import org.kde.kirigamiaddons.labs.components as Components
|
||||||
|
|
||||||
|
import Quotient
|
||||||
|
|
||||||
import org.kde.neochat
|
import org.kde.neochat
|
||||||
|
|
||||||
Kirigami.Dialog {
|
Kirigami.Dialog {
|
||||||
@@ -42,7 +44,7 @@ Kirigami.Dialog {
|
|||||||
ids.push(spaceGroup.buttons[i].modelData.id);
|
ids.push(spaceGroup.buttons[i].modelData.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
root.room.setJoinRule("restricted", ids);
|
root.room.setJoinRule(JoinRule.Restricted, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
QQC2.ButtonGroup {
|
QQC2.ButtonGroup {
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import QtQuick.Layouts
|
|||||||
import org.kde.kirigami as Kirigami
|
import org.kde.kirigami as Kirigami
|
||||||
import org.kde.kirigamiaddons.formcard as FormCard
|
import org.kde.kirigamiaddons.formcard as FormCard
|
||||||
|
|
||||||
|
import Quotient
|
||||||
|
|
||||||
import org.kde.neochat
|
import org.kde.neochat
|
||||||
|
|
||||||
FormCard.FormCardPage {
|
FormCard.FormCardPage {
|
||||||
@@ -45,23 +47,23 @@ FormCard.FormCardPage {
|
|||||||
FormCard.FormRadioDelegate {
|
FormCard.FormRadioDelegate {
|
||||||
text: i18nc("@option:check", "Private (invite only)")
|
text: i18nc("@option:check", "Private (invite only)")
|
||||||
description: i18n("Only invited people can join.")
|
description: i18n("Only invited people can join.")
|
||||||
checked: room.joinRule === "invite"
|
checked: room.joinRule === JoinRule.Invite
|
||||||
enabled: room.canSendState("m.room.join_rules")
|
enabled: room.canSendState("m.room.join_rules")
|
||||||
onCheckedChanged: if (checked && room.joinRule != "invite") {
|
onCheckedChanged: if (checked && room.joinRule != JoinRule.Invite) {
|
||||||
root.room.joinRule = "invite";
|
root.room.joinRule = JoinRule.Invite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FormCard.FormRadioDelegate {
|
FormCard.FormRadioDelegate {
|
||||||
text: i18nc("@option:check", "Space members")
|
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}` : "")
|
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)
|
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();
|
selectSpacesDialog.createObject(QQC2.Overlay.overlay).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
contentItem.children: QQC2.Button {
|
contentItem.children: QQC2.Button {
|
||||||
visible: root.room.joinRule === "restricted"
|
visible: root.room.joinRule === JoinRule.Restricted
|
||||||
text: i18n("Select spaces")
|
text: i18n("Select spaces")
|
||||||
icon.name: "list-add"
|
icon.name: "list-add"
|
||||||
|
|
||||||
@@ -82,20 +84,20 @@ FormCard.FormCardPage {
|
|||||||
FormCard.FormRadioDelegate {
|
FormCard.FormRadioDelegate {
|
||||||
text: i18nc("@option:check", "Knock")
|
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}` : "")
|
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
|
// https://spec.matrix.org/v1.4/rooms/#feature-matrix
|
||||||
enabled: room.canSendState("m.room.join_rules") && ["7", "8", "9", "10"].includes(room.version)
|
enabled: room.canSendState("m.room.join_rules") && ["7", "8", "9", "10"].includes(room.version)
|
||||||
onCheckedChanged: if (checked && room.joinRule != "knock") {
|
onCheckedChanged: if (checked && room.joinRule != JoinRule.Knock) {
|
||||||
root.room.joinRule = "knock";
|
root.room.joinRule = JoinRule.Knock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FormCard.FormRadioDelegate {
|
FormCard.FormRadioDelegate {
|
||||||
text: i18nc("@option:check", "Public")
|
text: i18nc("@option:check", "Public")
|
||||||
description: i18nc("@option:check", "Anyone can find and join.")
|
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")
|
enabled: room.canSendState("m.room.join_rules")
|
||||||
onCheckedChanged: if (checked && root.room.joinRule != "public") {
|
onCheckedChanged: if (checked && root.room.joinRule != JoinRule.Public) {
|
||||||
root.room.joinRule = "public";
|
root.room.joinRule = JoinRule.Public;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user