Page MenuHomePhorge

No OneTemporary

Size
7 KB
Referenced Files
None
Subscribers
None
diff --git a/src/contents/ui/Bubble.qml b/src/contents/ui/Bubble.qml
index 4f58859..5ab84eb 100644
--- a/src/contents/ui/Bubble.qml
+++ b/src/contents/ui/Bubble.qml
@@ -1,97 +1,84 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2020-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.13 as Kirigami
import '.' as Kazv
Kirigami.AbstractCard {
id: upper
default property var children
property var currentEvent: event
property var menuContent: []
readonly property var bubbleSpacing: leftPadding + rightPadding
Layout.fillWidth: false
TapHandler {
acceptedButtons: Qt.LeftButton | Qt.RightButton
property var menu: Menu {
objectName: 'bubbleContextMenu'
- property var deleteAction: Kirigami.Action {
+ Kirigami.Action {
text: l10n.get('event-delete')
onTriggered: eventView.redactSelf()
+ enabled: event && !event.redacted
}
- property var viewSourceAction: Kirigami.Action {
- text: l10n.get('event-view-source')
- onTriggered: eventSourcePopup.open()
- }
-
- property var separator: MenuSeparator {}
- property var menuItems: groups(
- (event && !event.redacted) ? [deleteAction, viewSourceAction] : [viewSourceAction],
- upper.menuContent
- )
+ MenuSeparator {}
- contentData: menuItems
-
- function groups(a, b) {
- if (a.length && b.length) {
- return [...a, separator, ...b];
- } else {
- return [...a, ...b];
- }
+ Kirigami.Action {
+ text: l10n.get('event-view-source')
+ onTriggered: eventSourcePopup.open()
}
}
onLongPressed: maybePopup()
onTapped: {
if (eventPoint.event.button === Qt.RightButton) {
maybePopup()
}
}
function shouldPopup() {
- return menu.menuItems.length
+ return true
}
function maybePopup() {
if (shouldPopup()) {
menu.popup(parent)
}
}
}
property var eventSourcePopup: Kirigami.OverlaySheet {
title: l10n.get('event-source-popup-title')
Kazv.EventSourceView {
event: upper.currentEvent
}
}
contentItem: RowLayout {
anchors.left: parent.left
anchors.right: parent.right
property var encryptedIcon: Kirigami.Icon {
source: 'emblem-encrypted-locked'
Layout.preferredHeight: inlineBadgeSize
Layout.preferredWidth: inlineBadgeSize
}
data: [
...(event && event.encrypted ? [encryptedIcon] : []),
...(Array.isArray(upper.children) ? upper.children :
upper.children ? [upper.children] : [])
]
}
}
diff --git a/src/tests/quick-tests/tst_EventView.qml b/src/tests/quick-tests/tst_EventView.qml
index 605783a..98ce219 100644
--- a/src/tests/quick-tests/tst_EventView.qml
+++ b/src/tests/quick-tests/tst_EventView.qml
@@ -1,166 +1,164 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.3
import QtQuick.Layouts 1.15
import QtTest 1.0
import '../../contents/ui' as Kazv
import 'test-helpers.js' as Helpers
import 'test-helpers' as TestHelpers
Item {
id: item
width: 800
height: 600
property var room: ({
test_resendMessageCalled: 0,
test_resendMessageLastTxnId: '',
resendMessage: (txnId) => {
++item.room.test_resendMessageCalled;
item.room.test_resendMessageLastTxnId = txnId;
}
})
property var l10n: Helpers.fluentMock
property var matrixSdk: TestHelpers.MatrixSdkMock {}
property var kazvIOManager: TestHelpers.KazvIOManagerMock {}
property var localEcho: ({
eventId: '',
sender: '',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.text',
body: 'some body',
},
encrypted: false,
isState: false,
unsignedData: {},
isLocalEcho: true,
isSending: true,
isFailed: false,
txnId: 'some-txn-id',
})
property var failedLocalEcho: Object.assign({}, item.localEcho, { isSending: false, isFailed: true, })
property var textEvent: ({
eventId: '',
sender: '',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.text',
body: 'some body',
},
})
property var redactedEvent: ({
eventId: '',
sender: '',
type: 'm.room.message',
stateKey: '',
content: {},
redacted: true,
})
property var imageEvent: ({
eventId: '',
sender: '',
type: 'm.room.message',
stateKey: '',
content: {
msgtype: 'm.image',
body: 'some body',
},
})
property var sender: ({
membership: 'join',
userId: '@foo:tusooa.xyz',
name: 'foo',
avatarMxcUri: '',
})
ColumnLayout {
Kazv.EventView {
id: eventView
event: item.localEcho
sender: item.sender
}
Kazv.EventView {
id: eventViewFailed
event: item.failedLocalEcho
sender: item.sender
}
Kazv.EventView {
id: eventViewText
event: item.textEvent
sender: item.sender
}
Kazv.EventView {
id: eventViewRedacted
event: item.redactedEvent
sender: item.sender
}
}
TestCase {
id: eventViewTest
name: 'EventViewTest'
when: windowShown
function init() {
eventView.event = item.localEcho;
item.room.test_resendMessageCalled = 0;
item.room.test_resendMessageLastTxnId = '';
}
function test_localEcho() {
const indicator = findChild(eventView, 'localEchoIndicator');
verify(indicator);
verify(indicator.source === 'state-sync');
verify(indicator.Accessible.name === l10n.get('event-sending'));
const resendButton = findChild(eventView, 'resendEventButton');
verify(resendButton);
verify(!resendButton.enabled);
}
function test_localEchoFailed() {
const indicator = findChild(eventViewFailed, 'localEchoIndicator');
verify(indicator);
verify(indicator.source === 'state-warning');
verify(indicator.Accessible.name === l10n.get('event-resend'));
const resendButton = findChild(eventViewFailed, 'resendEventButton');
verify(resendButton);
verify(resendButton.enabled);
mouseClick(indicator);
tryVerify(() => item.room.test_resendMessageCalled == 1);
tryVerify(() => item.room.test_resendMessageLastTxnId == 'some-txn-id');
}
function test_menuText() {
const menu = findChild(eventViewText, 'bubbleContextMenu');
verify(menu);
- tryVerify(() => menu.contentData && menu.contentData.length == 2);
- verify(menu.contentData[0].text === l10n.get('event-delete'));
+ tryVerify(() => menu.contentData[0].enabled);
}
function test_menuRedacted() {
const menu = findChild(eventViewRedacted, 'bubbleContextMenu');
verify(menu);
- verify(menu.menuItems && menu.menuItems.length == 1);
- verify(menu.contentData[0].text === l10n.get('event-view-source'));
+ tryVerify(() => !menu.contentData[0].enabled);
}
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 6:41 PM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55379
Default Alt Text
(7 KB)

Event Timeline