Page MenuHomePhorge

D139.1732490066.diff
No OneTemporary

Size
6 KB
Referenced Files
None
Subscribers
None

D139.1732490066.diff

diff --git a/src/contents/ui/CreateRoomPage.qml b/src/contents/ui/CreateRoomPage.qml
--- a/src/contents/ui/CreateRoomPage.qml
+++ b/src/contents/ui/CreateRoomPage.qml
@@ -20,6 +20,7 @@
property var creatingRoom: false
property var inviteUserIds: []
+ property var encryptedChangedOnce: false
ButtonGroup {
id: roomTypeButtons
@@ -34,6 +35,11 @@
id: typePublic
objectName: 'typePublicRadio'
checked: true
+ onCheckedChanged: {
+ if (!createRoomPage.encryptedChangedOnce) {
+ encrypted.checked = !checked;
+ }
+ }
text: l10n.get('create-room-page-type-public')
ButtonGroup.group: roomTypeButtons
}
@@ -82,6 +88,14 @@
Layout.fillWidth: true
}
+ CheckBox {
+ id: encrypted
+ objectName: 'encryptedInput'
+ text: l10n.get('create-room-page-encrypted-prompt')
+ Layout.fillWidth: true
+ onToggled: createRoomPage.encryptedChangedOnce = true
+ }
+
Item {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: l10n.get('create-room-invite-userids-prompt')
@@ -160,7 +174,8 @@
? MK.MatrixSdk.TrustedPrivateChat
: typePrivate.checked
? MK.MatrixSdk.PrivateChat
- : MK.MatrixSdk.PublicChat
+ : MK.MatrixSdk.PublicChat,
+ /* encrypted = */ encrypted.checked,
)
onResolved: {
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
@@ -254,6 +254,7 @@
create-room-page-action-create-room = 创建房间
create-room-page-success-prompt = 房间已创建。
create-room-page-failed-prompt = 无法创建房间。错误代码:{ $errorCode }。错误讯息:{ $errorMsg }。
+create-room-page-encrypted-prompt = 启用端对端加密
join-room-page-title = 加入房间
join-room-page-id-or-alias-prompt = 房间 id 或别名:
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
@@ -282,6 +282,7 @@
create-room-page-add-invite-placeholder = Matrix id, e.g. @foo:example.org
create-room-page-action-add-invite = Add
create-room-page-action-remove-invite = Remove
+create-room-page-encrypted-prompt = Enable end-to-end encryption
join-room-page-title = Join room
join-room-page-id-or-alias-prompt = Room id or alias:
diff --git a/src/matrix-sdk.hpp b/src/matrix-sdk.hpp
--- a/src/matrix-sdk.hpp
+++ b/src/matrix-sdk.hpp
@@ -158,6 +158,7 @@
* @param topic The topic of the room.
* @param powerLevelContentOverride The content to override m.room.power_levels event.
* @param preset The preset to create the room with.
+ * @param encrypted Whether to enable encryption for this room.
*/
MatrixPromise *createRoom(
bool isPrivate,
@@ -168,7 +169,8 @@
bool allowFederate,
const QString &topic,
const QJsonValue &powerLevelContentOverride,
- CreateRoomPreset preset
+ CreateRoomPreset preset,
+ bool encrypted
);
/**
diff --git a/src/matrix-sdk.cpp b/src/matrix-sdk.cpp
--- a/src/matrix-sdk.cpp
+++ b/src/matrix-sdk.cpp
@@ -551,9 +551,22 @@
bool allowFederate,
const QString &topic,
const QJsonValue &powerLevelContentOverride,
- CreateRoomPreset preset
+ CreateRoomPreset preset,
+ bool encrypted
)
{
+ immer::array<Event> initialState;
+
+ if (encrypted) {
+ initialState = {Event{json{
+ {"type", "m.room.encryption"},
+ {"state_key", ""},
+ {"content", {
+ {"algorithm", "m.megolm.v1.aes-sha2"},
+ }},
+ }}};
+ }
+
return new MatrixPromise(m_d->clientOnSecondaryRoot.createRoom(
isPrivate ? Kazv::RoomVisibility::Private : Kazv::RoomVisibility::Public,
optMaybe(name),
@@ -563,7 +576,8 @@
allowFederate,
optMaybe(topic),
nlohmann::json(powerLevelContentOverride),
- static_cast<Kazv::CreateRoomPreset>(preset)
+ static_cast<Kazv::CreateRoomPreset>(preset),
+ initialState
));
}
diff --git a/src/tests/quick-tests/tst_CreateRoomPage.qml b/src/tests/quick-tests/tst_CreateRoomPage.qml
--- a/src/tests/quick-tests/tst_CreateRoomPage.qml
+++ b/src/tests/quick-tests/tst_CreateRoomPage.qml
@@ -32,6 +32,7 @@
'topic',
'powerLevelContentOverride',
'preset',
+ 'encrypted',
])
}
property var sdkVars: ({})
@@ -56,6 +57,7 @@
mockHelper.clearAll();
createRoomPage.inviteUserIds = [];
createRoomPage.creatingRoom = false;
+ createRoomPage.encryptedChangedOnce = false;
}
function test_createRoomPublic() {
@@ -79,6 +81,7 @@
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.PublicChat,
+ encrypted: false,
}));
}
@@ -103,6 +106,7 @@
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.PrivateChat,
+ encrypted: true,
}));
}
@@ -127,6 +131,7 @@
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.TrustedPrivateChat,
+ encrypted: true,
}));
}
@@ -158,6 +163,7 @@
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.TrustedPrivateChat,
+ encrypted: true,
}));
}
@@ -193,6 +199,7 @@
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.TrustedPrivateChat,
+ encrypted: true,
}));
}
@@ -244,7 +251,28 @@
allowFederate: true,
powerLevelContentOverride: {},
preset: MK.MatrixSdk.PublicChat,
+ encrypted: false,
}));
}
+
+ function test_encryptedCheckBox() {
+ const publicRadio = findChild(createRoomPage, 'typePublicRadio');
+ const privateRadio = findChild(createRoomPage, 'typePrivateRadio');
+ const directRadio = findChild(createRoomPage, 'typeDirectRadio')
+ const encryptedInput = findChild(createRoomPage, 'encryptedInput');
+ mouseClick(publicRadio);
+ verify(!encryptedInput.checked);
+ mouseClick(privateRadio);
+ verify(encryptedInput.checked);
+ mouseClick(directRadio);
+ verify(encryptedInput.checked);
+
+ mouseClick(encryptedInput);
+ verify(!encryptedInput.checked);
+ mouseClick(publicRadio);
+ verify(!encryptedInput.checked);
+ mouseClick(directRadio);
+ verify(!encryptedInput.checked);
+ }
}
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 3:14 PM (18 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39943
Default Alt Text
D139.1732490066.diff (6 KB)

Event Timeline