From 054ad80d30ffc9c48710c8e691e3efc69ed25742 Mon Sep 17 00:00:00 2001 From: James Graham Date: Fri, 25 Nov 2022 16:13:01 +0000 Subject: [PATCH] Add history visibiltiy room setting Add setting for setting the history visibility. Note this setting can only be read not set for Quotient version < 0.7 as there is no event definition for a history visibility state event and it doesn't seem worth creating one when not needed with Quotient 0.7. BUG: 457840 --- src/neochatroom.cpp | 34 ++++++++++++++++++++++ src/neochatroom.h | 5 ++++ src/qml/RoomSettings/Security.qml | 47 +++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index d3edb1021..670b204ab 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -859,7 +859,15 @@ bool NeoChatRoom::canSendState(const QString &eventType) const auto pl = plEvent->powerLevelForState(eventType); auto currentPl = plEvent->powerLevelForUser(localUser()->id()); +#ifndef QUOTIENT_07 + if (eventType == "m.room.history_visibility") { + return false; + } else { + return currentPl >= pl; + } +#else return currentPl >= pl; +#endif } bool NeoChatRoom::readMarkerLoaded() const @@ -916,6 +924,32 @@ void NeoChatRoom::setJoinRule(const QString &joinRule) // Not emitting joinRuleChanged() here, since that would override the change in the UI with the *current* value, which is not the *new* value. } +QString NeoChatRoom::historyVisibility() const +{ +#ifdef QUOTIENT_07 + return currentState().get("m.room.history_visibility")->contentJson()["history_visibility"_ls].toString(); +#else + return getCurrentState("m.room.history_visibility")->contentJson()["history_visibility"_ls].toString(); +#endif +} + +void NeoChatRoom::setHistoryVisibility(const QString &historyVisibilityRule) +{ + if (!canSendState("m.room.history_visibility")) { + qWarning() << "Power level too low to set history visibility"; + return; + } + +#ifdef QUOTIENT_07 + setState("m.room.history_visibility", "", QJsonObject{{"history_visibility", historyVisibilityRule}}); +#else + qWarning() << "Quotient 0.7 required to set history visibility"; + return; +#endif + + // Not emitting historyVisibilityChanged() here, since that would override the change in the UI with the *current* value, which is not the *new* value. +} + QCoro::Task NeoChatRoom::doDeleteMessagesByUser(const QString &user, QString reason) { QStringList events; diff --git a/src/neochatroom.h b/src/neochatroom.h index 475297923..a295e40cd 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -48,6 +48,7 @@ class NeoChatRoom : public Quotient::Room Q_PROPERTY(QDateTime lastActiveTime READ lastActiveTime NOTIFY lastActiveTimeChanged) Q_PROPERTY(bool isInvite READ isInvite NOTIFY isInviteChanged) Q_PROPERTY(QString joinRule READ joinRule WRITE setJoinRule NOTIFY joinRuleChanged) + Q_PROPERTY(QString historyVisibility READ historyVisibility WRITE setHistoryVisibility NOTIFY historyVisibilityChanged) Q_PROPERTY(QString htmlSafeDisplayName READ htmlSafeDisplayName NOTIFY displayNameChanged) Q_PROPERTY(PushNotificationState::State pushNotificationState MEMBER m_currentPushNotificationState WRITE setPushNotificationState NOTIFY pushNotificationStateChanged) @@ -112,6 +113,9 @@ public: [[nodiscard]] QString joinRule() const; void setJoinRule(const QString &joinRule); + [[nodiscard]] QString historyVisibility() const; + void setHistoryVisibility(const QString &historyVisibilityRule); + [[nodiscard]] bool hasFileUploading() const { return m_hasFileUploading; @@ -258,6 +262,7 @@ Q_SIGNALS: void chatBoxAttachmentPathChanged(); void canEncryptRoomChanged(); void joinRuleChanged(); + void historyVisibilityChanged(); public Q_SLOTS: void uploadFile(const QUrl &url, const QString &body = QString()); diff --git a/src/qml/RoomSettings/Security.qml b/src/qml/RoomSettings/Security.qml index 5cc849f04..b22fac5ac 100644 --- a/src/qml/RoomSettings/Security.qml +++ b/src/qml/RoomSettings/Security.qml @@ -58,6 +58,53 @@ Kirigami.ScrollablePage { } } } + + MobileForm.FormCard { + Layout.topMargin: Kirigami.Units.largeSpacing + Layout.fillWidth: true + contentItem: ColumnLayout { + spacing: 0 + MobileForm.FormCardHeader { + title: i18nc("@option:check", "Message history visibility") + } + MobileForm.FormRadioDelegate { + text: i18nc("@option:check", "Anyone") + description: i18nc("@option:check", "Anyone, regardless of whether they have joined, can view history.") + checked: room.historyVisibility === "world_readable" + enabled: room.canSendState("m.room.history_visibility") + onCheckedChanged: if (checked) { + room.historyVisibility = "world_readable" + } + } + MobileForm.FormRadioDelegate { + text: i18nc("@option:check", "Members only") + description: i18nc("@option:check", "All members can view the entire message history, even before they joined.") + checked: room.historyVisibility === "shared" + enabled: room.canSendState("m.room.history_visibility") + onCheckedChanged: if (checked) { + room.historyVisibility = "shared" + } + } + MobileForm.FormRadioDelegate { + text: i18nc("@option:check", "Members only (since invite)") + description: i18nc("@option:check", "New members can view the message history from the point they were invited to the room.") + checked: room.historyVisibility === "invited" + enabled: room.canSendState("m.room.history_visibility") + onCheckedChanged: if (checked) { + room.historyVisibility = "invited" + } + } + MobileForm.FormRadioDelegate { + text: i18nc("@option:check", "Members only (since joining)") + description: i18nc("@option:check", "New members can view the message history from the point they joined the room.") + checked: room.historyVisibility === "joined" + enabled: room.canSendState("m.room.history_visibility") + onCheckedChanged: if (checked) { + room.historyVisibility = "joined" + } + } + } + } } footer: QQC2.ToolBar {