Implement changing join rules
This commit is contained in:
@@ -874,6 +874,20 @@ QString NeoChatRoom::joinRule() const
|
||||
return getCurrentState<JoinRulesEvent>()->joinRule();
|
||||
}
|
||||
|
||||
void NeoChatRoom::setJoinRule(const QString &joinRule)
|
||||
{
|
||||
if (!canSendState("m.room.join_rules")) {
|
||||
qWarning() << "Power level too low to set join rules";
|
||||
return;
|
||||
}
|
||||
#ifdef QUOTIENT_07
|
||||
setState("m.room.join_rules", "", QJsonObject{{"join_rule", joinRule}});
|
||||
#else
|
||||
setState<JoinRulesEvent>(QJsonObject{{"type", "m.room.join_rules"}, {"state_key", ""}, {"content", QJsonObject{{"join_rule", joinRule}}}});
|
||||
#endif
|
||||
// Not emitting joinRuleChanged() here, since that would override the change in the UI with the *current* value, which is not the *new* value.
|
||||
}
|
||||
|
||||
QCoro::Task<void> NeoChatRoom::doDeleteMessagesByUser(const QString &user)
|
||||
{
|
||||
QStringList events;
|
||||
|
||||
@@ -49,7 +49,7 @@ class NeoChatRoom : public Quotient::Room
|
||||
Q_PROPERTY(bool readMarkerLoaded READ readMarkerLoaded NOTIFY readMarkerLoadedChanged)
|
||||
Q_PROPERTY(QDateTime lastActiveTime READ lastActiveTime NOTIFY lastActiveTimeChanged)
|
||||
Q_PROPERTY(bool isInvite READ isInvite NOTIFY isInviteChanged)
|
||||
Q_PROPERTY(QString joinRule READ joinRule CONSTANT)
|
||||
Q_PROPERTY(QString joinRule READ joinRule WRITE setJoinRule NOTIFY joinRuleChanged)
|
||||
Q_PROPERTY(QString htmlSafeDisplayName READ htmlSafeDisplayName NOTIFY displayNameChanged)
|
||||
Q_PROPERTY(PushNotificationState::State pushNotificationState MEMBER m_currentPushNotificationState WRITE setPushNotificationState NOTIFY
|
||||
pushNotificationStateChanged)
|
||||
@@ -112,6 +112,7 @@ public:
|
||||
bool isEventHighlighted(const Quotient::RoomEvent *e) const;
|
||||
|
||||
[[nodiscard]] QString joinRule() const;
|
||||
void setJoinRule(const QString &joinRule);
|
||||
|
||||
[[nodiscard]] bool hasFileUploading() const
|
||||
{
|
||||
@@ -254,6 +255,7 @@ Q_SIGNALS:
|
||||
void chatBoxEditIdChanged();
|
||||
void chatBoxAttachmentPathChanged();
|
||||
void canEncryptRoomChanged();
|
||||
void joinRuleChanged();
|
||||
|
||||
public Q_SLOTS:
|
||||
void uploadFile(const QUrl &url, const QString &body = QString());
|
||||
|
||||
@@ -24,7 +24,10 @@ Kirigami.ScrollablePage {
|
||||
text: i18nc("@option:check", "Private (invite only)")
|
||||
Kirigami.FormData.label: i18nc("@option:check", "Access:")
|
||||
checked: room.joinRule === "invite"
|
||||
enabled: false
|
||||
enabled: room.canSendState("m.room.join_rules")
|
||||
onCheckedChanged: if (checked) {
|
||||
room.joinRule = "invite";
|
||||
}
|
||||
}
|
||||
QQC2.Label {
|
||||
text: i18n("Only invited people can join.")
|
||||
@@ -33,19 +36,32 @@ Kirigami.ScrollablePage {
|
||||
QQC2.RadioButton {
|
||||
text: i18nc("@option:check", "Space members")
|
||||
checked: room.joinRule === "restricted"
|
||||
enabled: false
|
||||
enabled: room.canSendState("m.room.join_rules") && ["8", "9", "10"].includes(room.version) && false
|
||||
onCheckedChanged: if (checked) {
|
||||
room.joinRule = "restricted";
|
||||
}
|
||||
}
|
||||
QQC2.Label {
|
||||
text: i18n("Anyone in a space can find and join.")
|
||||
wrapMode: Qt.Wrap
|
||||
width: root.width
|
||||
font: Kirigami.Theme.smallFont
|
||||
}
|
||||
QQC2.Label {
|
||||
font: Kirigami.Theme.smallFont
|
||||
visible: !["8", "9", "10"].includes(room.version)
|
||||
text: i18n("You need to upgrade this room to a newer version to enable this setting.")
|
||||
}
|
||||
QQC2.RadioButton {
|
||||
text: i18nc("@option:check", "Public")
|
||||
checked: room.joinRule === "public"
|
||||
enabled: false
|
||||
enabled: room.canSendState("m.room.join_rules")
|
||||
onCheckedChanged: if (checked) {
|
||||
room.joinRule = "public";
|
||||
}
|
||||
}
|
||||
QQC2.Label {
|
||||
text: i18nc("@option:check", "Anyone can find and join.") + room.joinRule
|
||||
text: i18nc("@option:check", "Anyone can find and join.")
|
||||
font: Kirigami.Theme.smallFont
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user