Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F140541
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/contents/ui/room-settings/RoomSettingsPage.qml b/src/contents/ui/room-settings/RoomSettingsPage.qml
index 51b0253..59940c8 100644
--- a/src/contents/ui/room-settings/RoomSettingsPage.qml
+++ b/src/contents/ui/room-settings/RoomSettingsPage.qml
@@ -1,237 +1,239 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import org.kde.kirigami 2.20 as Kirigami
import moe.kazv.mxc.kazv 0.0 as MK
import '../matrix-helpers.js' as Helpers
import '..' as Kazv
import '.' as RoomSettings
Kazv.ClosableScrollablePage {
id: roomSettingsPage
property var room
property var roomNameProvider: Kazv.RoomNameProvider {
room: roomSettingsPage.room
}
property var roomDisplayName: roomNameProvider.name
property var customTagIds: room.tagIds.filter(k => k.startsWith('u.'))
title: l10n.get('room-settings-page-title', { room: roomDisplayName })
function tagIdToName(tagId) {
return tagId.slice(2);
}
property var encryptionPopup: Kirigami.PromptDialog {
parent: roomSettingsPage.overlay
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
}
ColumnLayout {
Button {
text: l10n.get('room-settings-members-action')
Layout.fillWidth: true
onClicked: pageStack.push(Qt.resolvedUrl('qrc:/room-settings/RoomMemberListPage.qml'), { room: room, members: room.members() })
}
Button {
text: l10n.get('room-settings-banned-members-action')
Layout.fillWidth: true
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
}
CheckBox {
text: l10n.get('room-settings-favourited')
checkable: true
checked: tagHandler.hasTag('m.favourite')
enabled: tagHandler.available
onToggled: tagHandler.toggleTag('m.favourite')
}
ListView {
model: customTagIds.length
Layout.fillWidth: true
Layout.fillHeight: true
Layout.minimumHeight: childrenRect.height
delegate: Kirigami.SwipeListItem {
required property var index
Label {
text: tagIdToName(customTagIds[index])
}
actions: [
Kirigami.Action {
enabled: tagHandler.available
icon.name: 'list-remove-symbolic'
text: l10n.get('room-settings-remove-tag')
onTriggered: tagHandler.toggleTag(customTagIds[index])
}
]
}
}
RowLayout {
TextField {
id: newTagName
enabled: tagHandler.available
text: ''
Layout.fillWidth: true
}
Button {
enabled: tagHandler.available
text: l10n.get('room-settings-add-tag')
onClicked: {
tagHandler.toggleTag('u.' + newTagName.text)
}
}
Connections {
target: tagHandler
function onTagAdded(tagId) {
if (tagId === 'u.' + newTagName.text) {
newTagName.text = '';
}
}
}
}
Button {
text: l10n.get('room-invite-action')
Layout.fillWidth: true
onClicked: {
activateRoomInvitePage(roomSettingsPage.room);
}
}
Button {
+ objectName: 'leaveRoomButton'
text: l10n.get('room-leave-action')
Layout.fillWidth: true
onClicked: {
confirmLeaveOverlay.open();
}
}
Button {
objectName: 'forgetRoomButton'
text: l10n.get('room-forget-action')
Layout.fillWidth: true
visible: room.membership === MK.MatrixRoom.Leave
onClicked: {
confirmForgetOverlay.open();
}
}
}
property var confirmLeaveOverlay: Kazv.ConfirmationOverlay {
+ objectName: 'confirmLeaveRoomPopup'
parent: roomSettingsPage.overlay
title: l10n.get('room-leave-confirm-popup-title')
message: l10n.get('room-leave-confirm-popup-message')
confirmActionText: l10n.get('room-leave-confirm-popup-confirm-action')
cancelActionText: l10n.get('room-leave-confirm-popup-cancel-action')
onAccepted: leaveRoomHandler.call()
}
property var leaveRoomHandler: Kazv.AsyncHandler {
trigger: () => room.leaveRoom()
onResolved: {
if (success) {
- showPassiveNotification(l10n.get('leave-room-success-prompt', { room: roomId }));
+ showPassiveNotification(l10n.get('leave-room-success-prompt', { room: room.roomId }));
inviteOverlay.close();
} else {
- showPassiveNotification(l10n.get('leave-room-failed-prompt', { room: roomId, errorCode: data.errorCode, errorMsg: data.error }));
+ showPassiveNotification(l10n.get('leave-room-failed-prompt', { room: room.roomId, errorCode: data.errorCode, errorMsg: data.error }));
}
}
}
property var confirmForgetOverlay: Kazv.ConfirmationOverlay {
objectName: 'confirmForgetRoomPopup'
parent: roomSettingsPage.overlay
title: l10n.get('room-forget-confirm-popup-title')
message: l10n.get('room-forget-confirm-popup-message')
confirmActionText: l10n.get('room-forget-confirm-popup-confirm-action')
cancelActionText: l10n.get('room-forget-confirm-popup-cancel-action')
onAccepted: forgetRoomHandler.call()
}
property var forgetRoomHandler: Kazv.AsyncHandler {
trigger: () => room.forgetRoom()
onResolved: (success, data) => {
if (success) {
showPassiveNotification(l10n.get('forget-room-success-prompt', { room: room.roomId }));
} else {
showPassiveNotification(l10n.get('forget-room-failed-prompt', { room: room.roomId, errorCode: data.errorCode, errorMsg: data.error }));
}
}
}
}
diff --git a/src/tests/quick-tests/tst_RoomSettingsPage.qml b/src/tests/quick-tests/tst_RoomSettingsPage.qml
index af8c443..4ddc982 100644
--- a/src/tests/quick-tests/tst_RoomSettingsPage.qml
+++ b/src/tests/quick-tests/tst_RoomSettingsPage.qml
@@ -1,121 +1,141 @@
/*
* 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 mockHelper: TestHelpers.MockHelper {}
property var roomUnencrypted: Helpers.factory.room({
membership: MK.MatrixRoom.Join,
encrypted: false,
sendStateEvent: mockHelper.promise(),
})
property var roomEncrypted: Helpers.factory.room({
membership: MK.MatrixRoom.Join,
encrypted: true,
})
property var roomLeft: Helpers.factory.room({
membership: MK.MatrixRoom.Leave,
forgetRoom: mockHelper.promise(),
})
property var roomJoined: Helpers.factory.room({
- membership: MK.MatrixRoom.Join
+ membership: MK.MatrixRoom.Join,
+ leaveRoom: mockHelper.promise(),
})
property var showPassiveNotification: mockHelper.noop()
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
}
KazvRS.RoomSettingsPage {
id: pageLeft
room: item.roomLeft
}
KazvRS.RoomSettingsPage {
id: pageJoined
room: item.roomJoined
}
}
TestCase {
id: roomSettingsPageTest
name: 'RoomSettingsPageTest'
when: windowShown
function init() {
mockHelper.clearAll();
}
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.sendStateEvent.lastArgs()[0].type === 'm.room.encryption');
tryVerify(() => roomUnencrypted.sendStateEvent.lastArgs()[0].state_key === '');
verify(!findChild(pageUnencrypted, 'enableEncryptionButton').enabled);
roomUnencrypted.sendStateEvent.lastRetVal().resolve(true, {});
tryVerify(() => findChild(pageUnencrypted, 'enableEncryptionButton').enabled);
}
function test_forgetRoom() {
const forgetRoomButton = findChild(pageLeft, 'forgetRoomButton');
const confirmPopup = findChild(pageLeft, 'confirmForgetRoomPopup');
verify(forgetRoomButton.visible);
verify(!findChild(pageJoined, 'forgetRoomButton').visible);
confirmPopup.accepted();
tryVerify(() => roomLeft.forgetRoom.calledTimes() === 1);
roomLeft.forgetRoom.lastRetVal().resolve(true, {});
tryVerify(() => item.showPassiveNotification.calledTimes() === 1);
}
function test_forgetRoomFailure() {
const confirmPopup = findChild(pageLeft, 'confirmForgetRoomPopup');
confirmPopup.accepted();
roomLeft.forgetRoom.lastRetVal().resolve(false, {});
tryVerify(() => item.showPassiveNotification.calledTimes() === 1);
}
+
+ function test_leaveRoom() {
+ const leaveRoomButton = findChild(pageJoined, 'leaveRoomButton');
+ const confirmPopup = findChild(pageJoined, 'confirmLeaveRoomPopup');
+ verify(leaveRoomButton.visible);
+
+ confirmPopup.accepted();
+ tryVerify(() => roomJoined.leaveRoom.calledTimes() === 1);
+ roomJoined.leaveRoom.lastRetVal().resolve(true, {});
+ console.log(roomJoined.membership);
+ tryVerify(() => item.showPassiveNotification.calledTimes() === 1);
+ }
+
+ function test_leaveRoomFailure() {
+ const confirmPopup = findChild(pageJoined, 'confirmLeaveRoomPopup');
+ confirmPopup.accepted();
+ roomJoined.leaveRoom.lastRetVal().resolve(false, {});
+ tryVerify(() => item.showPassiveNotification.calledTimes() === 1);
+ }
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 11:59 PM (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55533
Default Alt Text
(12 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment