Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112100
D33.1732271272.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D33.1732271272.diff
View Options
diff --git a/src/contents/ui/room-settings/RoomSettingsPage.qml b/src/contents/ui/room-settings/RoomSettingsPage.qml
--- a/src/contents/ui/room-settings/RoomSettingsPage.qml
+++ b/src/contents/ui/room-settings/RoomSettingsPage.qml
@@ -8,7 +8,7 @@
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
-import org.kde.kirigami 2.13 as Kirigami
+import org.kde.kirigami 2.20 as Kirigami
import '../matrix-helpers.js' as Helpers
@@ -28,6 +28,45 @@
return tagId.slice(2);
}
+ property var encryptionPopup: Kirigami.PromptDialog {
+ objectName: 'encryptionPopup'
+ title: l10n.get('room-settings-enable-encryption-prompt-dialog-title')
+ standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
+
+ ColumnLayout {
+ Label {
+ Layout.fillWidth: true
+ text: l10n.get('room-settings-enable-encryption-prompt-dialog-prompt')
+ wrapMode: Text.Wrap
+ }
+ }
+
+ onAccepted: enableEncryption.call()
+ }
+
+ property var enablingEncryption: false
+ property var enableEncryption: Kazv.AsyncHandler {
+ trigger: () => {
+ roomSettingsPage.enablingEncryption = true;
+ return room.sendStateEvent({
+ type: 'm.room.encryption',
+ state_key: '',
+ content: {
+ algorithm: 'm.megolm.v1.aes-sha2',
+ },
+ });
+ }
+
+ onResolved: (success, data) => {
+ roomSettingsPage.enablingEncryption = false;
+ if (success) {
+ showPassiveNotification(l10n.get('room-settings-encryption-enabled-notification'));
+ } else {
+ showPassiveNotification(l10n.get('room-settings-encryption-failed-to-enable-notification', { errorCode: data.errorCode, errorMsg: data.error }));
+ }
+ }
+ }
+
property var tagHandler: RoomSettings.RoomTagHandler {
room: roomSettingsPage.room
}
@@ -45,6 +84,21 @@
onClicked: pageStack.push(Qt.resolvedUrl('qrc:/room-settings/RoomMemberListPage.qml'), { room: room, members: room.bannedMembers() })
}
+ Label {
+ objectName: 'encryptionIndicator'
+ Layout.fillWidth: true
+ text: !!room.encrypted ? l10n.get('room-settings-encrypted') : l10n.get('room-settings-not-encrypted')
+ }
+
+ Button {
+ objectName: 'enableEncryptionButton'
+ Layout.fillWidth: true
+ visible: !room.encrypted
+ enabled: !roomSettingsPage.enablingEncryption
+ text: l10n.get('room-settings-enable-encryption-action')
+ onClicked: encryptionPopup.open()
+ }
+
Label {
text: l10n.get('room-settings-tags')
Layout.fillWidth: true
diff --git a/src/l10n/cmn-Hans/100-ui.ftl b/src/l10n/cmn-Hans/100-ui.ftl
--- a/src/l10n/cmn-Hans/100-ui.ftl
+++ b/src/l10n/cmn-Hans/100-ui.ftl
@@ -76,6 +76,13 @@
room-settings-add-tag = 添加标签
room-settings-members-action = 房间成员...
room-settings-banned-members-action = 被封禁的成员...
+room-settings-enable-encryption-prompt-dialog-title = 启用加密
+room-settings-enable-encryption-prompt-dialog-prompt = 一旦在本房间中启用了加密,就不能再禁用了。确定吗?
+room-settings-enable-encryption-action = 启用加密
+room-settings-encrypted = 本房间中的消息是端对端加密了的。
+room-settings-not-encrypted = 本房间中的消息没有端对端加密。
+room-settings-encryption-enabled-notification = 本房间中的加密已经启用。
+room-settings-encryption-failed-to-enable-notification = 不能在本房间中启用加密。错误代码:{ $errorCode }。错误讯息:{ $errorMsg }。
room-member-list-page-title = { $room } 的成员
diff --git a/src/l10n/en/100-ui.ftl b/src/l10n/en/100-ui.ftl
--- a/src/l10n/en/100-ui.ftl
+++ b/src/l10n/en/100-ui.ftl
@@ -76,6 +76,13 @@
room-settings-add-tag = Add tag
room-settings-members-action = Room members...
room-settings-banned-members-action = Banned members...
+room-settings-enable-encryption-prompt-dialog-title = Enabling encryption
+room-settings-enable-encryption-prompt-dialog-prompt = Once you enable encryption in this room, you cannot disable it again. Are you sure?
+room-settings-enable-encryption-action = Enable encryption
+room-settings-encrypted = Messages in this room are end-to-end encrypted.
+room-settings-not-encrypted = Messages in this room are not end-to-end-encrypted.
+room-settings-encryption-enabled-notification = Encryption is now enabled in this room.
+room-settings-encryption-failed-to-enable-notification = Cannot enable encryption in this room. Error code: { $errorCode }. Error message: { $errorMsg }.
room-member-list-page-title = Members of { $room }
diff --git a/src/matrix-room.hpp b/src/matrix-room.hpp
--- a/src/matrix-room.hpp
+++ b/src/matrix-room.hpp
@@ -83,6 +83,8 @@
Q_INVOKABLE void resendMessage(QString txnId) const;
+ Q_INVOKABLE MatrixPromise *sendStateEvent(const QJsonObject &eventJson) const;
+
Q_INVOKABLE MatrixPromise *redactEvent(QString eventId, QString reason) const;
Q_INVOKABLE MatrixPromise *removeLocalEcho(QString txnId) const;
diff --git a/src/matrix-room.cpp b/src/matrix-room.cpp
--- a/src/matrix-room.cpp
+++ b/src/matrix-room.cpp
@@ -213,6 +213,11 @@
m_room.resendMessage(txnId.toStdString());
}
+MatrixPromise *MatrixRoom::sendStateEvent(const QJsonObject &eventJson) const
+{
+ return new MatrixPromise(m_room.sendStateEvent(Event(json(eventJson))));
+}
+
nlohmann::json MatrixRoom::makeMediaFileMessageJson(QString fileName, QString mimeType, qint64 fileSize, QString mxcUri) const
{
static auto available_msgtype = std::array<std::string, 3>{"m.audio", "m.video", "m.image"};
diff --git a/src/tests/quick-tests/tst_RoomSettingsPage.qml b/src/tests/quick-tests/tst_RoomSettingsPage.qml
new file mode 100644
--- /dev/null
+++ b/src/tests/quick-tests/tst_RoomSettingsPage.qml
@@ -0,0 +1,87 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtQuick 2.15
+import QtQuick.Layouts 1.15
+import QtTest 1.0
+
+import '../../contents/ui' as Kazv
+import '../../contents/ui/room-settings' as KazvRS
+import moe.kazv.mxc.kazv 0.0 as MK
+
+import 'test-helpers.js' as Helpers
+import 'test-helpers' as TestHelpers
+
+Item {
+ id: item
+ width: 800
+ height: 600
+
+ property var promiseComp: Component {
+ TestHelpers.MatrixPromiseMock {}
+ }
+
+ property var roomUnencrypted: Helpers.factory.room({
+ membership: MK.MatrixRoom.Join,
+ encrypted: false,
+ _sendStatePromise: undefined,
+ _sendStateArg: undefined,
+ sendStateEvent(event) {
+ roomUnencrypted._sendStatePromise = promiseComp.createObject(item);
+ roomUnencrypted._sendStateArg = event;
+ return roomUnencrypted._sendStatePromise;
+ },
+ })
+
+ property var roomEncrypted: Helpers.factory.room({
+ membership: MK.MatrixRoom.Join,
+ encrypted: true,
+ })
+
+ function showPassiveNotification() {
+ }
+
+ property var l10n: Helpers.fluentMock
+ property var matrixSdk: TestHelpers.MatrixSdkMock {
+ property var userId: '@foo:example.org'
+ }
+ property var sdkVars: ({})
+
+ ColumnLayout {
+ KazvRS.RoomSettingsPage {
+ id: pageUnencrypted
+ room: item.roomUnencrypted
+ }
+
+ KazvRS.RoomSettingsPage {
+ id: pageEncrypted
+ room: item.roomEncrypted
+ }
+ }
+
+ TestCase {
+ id: roomSettingsPageTest
+ name: 'RoomSettingsPageTest'
+ when: windowShown
+
+ function test_encryptionIndicator() {
+ compare(findChild(pageUnencrypted, 'encryptionIndicator').text, l10n.get('room-settings-not-encrypted'));
+ verify(findChild(pageUnencrypted, 'enableEncryptionButton').visible);
+
+ compare(findChild(pageEncrypted, 'encryptionIndicator').text, l10n.get('room-settings-encrypted'));
+ verify(!findChild(pageEncrypted, 'enableEncryptionButton').visible);
+ }
+
+ function test_enableEncryption() {
+ pageUnencrypted.encryptionPopup.accepted();
+ tryVerify(() => roomUnencrypted._sendStateArg.type === 'm.room.encryption');
+ tryVerify(() => roomUnencrypted._sendStateArg.state_key === '');
+ verify(!findChild(pageUnencrypted, 'enableEncryptionButton').enabled);
+ roomUnencrypted._sendStatePromise.resolve(true, {});
+ tryVerify(() => findChild(pageUnencrypted, 'enableEncryptionButton').enabled);
+ }
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 2:27 AM (11 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38793
Default Alt Text
D33.1732271272.diff (8 KB)
Attached To
Mode
D33: Support enabling encryption in a room
Attached
Detach File
Event Timeline
Log In to Comment