Page MenuHomePhorge

D125.1732646735.diff
No OneTemporary

Size
8 KB
Referenced Files
None
Subscribers
None

D125.1732646735.diff

diff --git a/src/contents/ui/Bubble.qml b/src/contents/ui/Bubble.qml
--- a/src/contents/ui/Bubble.qml
+++ b/src/contents/ui/Bubble.qml
@@ -82,7 +82,7 @@
Kirigami.Action {
objectName: 'deleteMenuItem'
text: l10n.get('event-delete')
- onTriggered: eventView.redactSelf()
+ onTriggered: deleteEventRequested(index)
enabled: event && !event.redacted
},
Kirigami.Action {
diff --git a/src/contents/ui/EventView.qml b/src/contents/ui/EventView.qml
--- a/src/contents/ui/EventView.qml
+++ b/src/contents/ui/EventView.qml
@@ -29,7 +29,6 @@
property var iconSize: Kirigami.Units.iconSizes.large
property var inlineBadgeSize: Kirigami.Units.iconSizes.smallMedium
property var senderNameSize: Kirigami.Units.gridUnit * 1.2
- property var redactPromise: null
property var isGapped: false
property var compactMode: false
@@ -251,25 +250,6 @@
}
}
- function redactSelf(reason) {
- if (eventView.event.eventId) {
- eventView.redactPromise = room.redactEvent(eventView.event.eventId, reason);
- } else {
- // this is a local echo
- eventView.redactPromise = room.removeLocalEcho(eventView.event.txnId);
- }
- }
-
- Connections {
- target: eventView.redactPromise
- function onResolved(success, data) {
- if (!success) {
- showPassiveNotification(l10n.get('event-delete-failed', { errorMsg: data.error, errorCode: data.errorCode }));
- }
- eventView.redactPromise = null;
- }
- }
-
function paginateBack() {
paginateBackRequested(event.eventId);
}
diff --git a/src/contents/ui/RoomTimelineView.qml b/src/contents/ui/RoomTimelineView.qml
--- a/src/contents/ui/RoomTimelineView.qml
+++ b/src/contents/ui/RoomTimelineView.qml
@@ -22,6 +22,7 @@
signal pinEventRequested(string eventId)
signal unpinEventRequested(string eventId)
+ signal deleteEventRequested(index: int)
property var pinEvent: Kazv.AsyncHandler {
property var eventIds
@@ -47,6 +48,27 @@
}
}
+ property var deleteEvent: Kazv.AsyncHandler {
+ property var eventId
+ property var reason
+ trigger: () => room.redactEvent(eventId, reason)
+ onResolved: (success, data) => {
+ if (!success) {
+ showPassiveNotification(l10n.get('event-delete-failed', { errorMsg: data.error, errorCode: data.errorCode }));
+ }
+ }
+ }
+
+ property var deleteLocalEcho: Kazv.AsyncHandler {
+ property var txnId
+ trigger: () => room.removeLocalEcho(txnId)
+ onResolved: (success, data) => {
+ if (!success) {
+ showPassiveNotification(l10n.get('event-delete-failed', { errorMsg: data.error, errorCode: data.errorCode }));
+ }
+ }
+ }
+
onPinEventRequested: (eventId) => {
pinEventPopupComp.createObject(Overlay.overlay, { eventId }).open()
}
@@ -55,6 +77,10 @@
unpinEventPopupComp.createObject(Overlay.overlay, { eventId }).open()
}
+ onDeleteEventRequested: (index) => {
+ confirmDeletionPopupComp.createObject(Overlay.overlay, { index }).open()
+ }
+
property var pinEventPopupComp: Component {
Kazv.ConfirmationOverlay {
objectName: 'pinEventPopup'
@@ -99,6 +125,34 @@
}
}
+ property var confirmDeletionPopupComp: Component {
+ Kazv.ConfirmationOverlay {
+ objectName: 'confirmDeletionPopup'
+ property int index
+ shouldSelfDestroy: true
+ title: l10n.get('confirm-deletion-popup-title')
+ message: l10n.get('confirm-deletion-popup-message')
+ confirmActionText: l10n.get('confirm-deletion-popup-confirm-action')
+ cancelActionText: l10n.get('confirm-deletion-popup-cancel-action')
+ onAccepted: {
+ if (eventView.event.isLocalEcho) {
+ deleteLocalEcho.txnId = eventView.event.txnId;
+ deleteLocalEcho.call();
+ } else {
+ deleteEvent.eventId = eventView.event.eventId;
+ deleteEvent.call();
+ }
+ }
+
+ EventViewWrapper {
+ id: eventView
+ Layout.fillWidth: true
+ event: timeline.at(index)
+ compactMode: true
+ }
+ }
+ }
+
spacing: 0
model: timeline
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
@@ -353,3 +353,8 @@
confirm-logout-popup-prompt = 你确定要登出吗?
confirm-logout-popup-accept-button = 是
confirm-logout-popup-cancel-button = 取消
+
+confirm-deletion-popup-title = 删除事件
+confirm-deletion-popup-message = 你确定要删除这个事件吗?
+confirm-deletion-popup-confirm-action = 删除
+confirm-deletion-popup-cancel-action = 取消
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
@@ -381,3 +381,8 @@
confirm-logout-popup-prompt = Are you sure to logout?
confirm-logout-popup-accept-button = Yes
confirm-logout-popup-cancel-button = Cancel
+
+confirm-deletion-popup-title = Delete event
+confirm-deletion-popup-message = Are you sure you want to delete this event?
+confirm-deletion-popup-confirm-action = Delete
+confirm-deletion-popup-cancel-action = Cancel
diff --git a/src/tests/quick-tests/tst_EventView.qml b/src/tests/quick-tests/tst_EventView.qml
--- a/src/tests/quick-tests/tst_EventView.qml
+++ b/src/tests/quick-tests/tst_EventView.qml
@@ -26,6 +26,7 @@
property var viewEventHistoryRequested: mockHelper.noop()
property var pinEventRequested: mockHelper.noop()
property var unpinEventRequested: mockHelper.noop()
+ property var deleteEventRequested: mockHelper.noop()
property var timeline: ({
gaps: [],
@@ -320,6 +321,7 @@
id: eventViewFailed
event: item.failedLocalEcho
sender: item.sender
+ property int index: 0
}
Kazv.EventView {
@@ -497,11 +499,9 @@
const menuComp = findChild(eventViewFailed, 'bubble').menuComp;
const menu = menuComp.createObject(menuComp.parent);
const deleteAction = findChild(menu, 'deleteMenuItem');
+ verify(deleteAction.enabled);
deleteAction.trigger();
-
- tryVerify(() => item.room.removeLocalEcho.calledTimes() === 1);
- tryVerify(() => item.room.removeLocalEcho.lastArgs()[0] === 'some-txn-id');
- verify(item.room.resendMessage.calledTimes() === 0);
+ compare(deleteEventRequested.calledTimes(), 1);
}
function test_sentMessage() {
diff --git a/src/tests/quick-tests/tst_RoomTimelineView.qml b/src/tests/quick-tests/tst_RoomTimelineView.qml
--- a/src/tests/quick-tests/tst_RoomTimelineView.qml
+++ b/src/tests/quick-tests/tst_RoomTimelineView.qml
@@ -58,6 +58,8 @@
property var room: ({
pinEvents: mockHelper.promise(),
unpinEvents: mockHelper.promise(),
+ redactEvent: mockHelper.promise(),
+ removeLocalEcho: mockHelper.promise(),
messageById(id) {
return { eventId: id };
},
@@ -166,5 +168,35 @@
compare(showPassiveNotification.calledTimes(), 1);
compare(showPassiveNotification.lastArgs()[0], l10n.get('event-unpin-failed-prompt', { errorCode: 'M_FORBIDDEN', errorMsg: 'You are not allowed to do so' }));
}
+
+ function test_deleteEvent() {
+ roomTimelineView.deleteEventRequested(1);
+ const popup = findChild(Overlay.overlay, 'confirmDeletionPopup');
+ verify(popup);
+ tryVerify(() => popup.opened);
+ mouseClick(findChild(popup, 'confirmButton'));
+ verify(room.redactEvent.calledTimes() === 1);
+ verify(room.redactEvent.lastArgs()[0], ['$1']);
+ tryVerify(() => !popup.opened);
+ tryVerify(() => !findChild(Overlay.overlay, 'confirmDeletionPopup'));
+ room.redactEvent.lastRetVal().resolve(false, { errorCode: 'M_FORBIDDEN', error: 'You are not allowed to do so' });
+ compare(showPassiveNotification.calledTimes(), 1);
+ compare(showPassiveNotification.lastArgs()[0], l10n.get('event-delete-failed', { errorMsg: 'You are not allowed to do so', errorCode: 'M_FORBIDDEN' }));
+ }
+
+ function test_deleteLocalEcho() {
+ roomTimelineView.deleteEventRequested(0);
+ const popup = findChild(Overlay.overlay, 'confirmDeletionPopup');
+ verify(popup);
+ tryVerify(() => popup.opened);
+ mouseClick(findChild(popup, 'confirmButton'));
+ verify(room.removeLocalEcho.calledTimes() === 1);
+ verify(room.removeLocalEcho.lastArgs()[0], ['$0']);
+ tryVerify(() => !popup.opened);
+ tryVerify(() => !findChild(Overlay.overlay, 'confirmDeletionPopup'));
+ room.removeLocalEcho.lastRetVal().resolve(false, { errorCode: 'M_FORBIDDEN', error: 'You are not allowed to do so' });
+ compare(showPassiveNotification.calledTimes(), 1);
+ compare(showPassiveNotification.lastArgs()[0], l10n.get('event-delete-failed', { errorMsg: 'You are not allowed to do so', errorCode: 'M_FORBIDDEN' }));
+ }
}
}

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 10:45 AM (21 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40616
Default Alt Text
D125.1732646735.diff (8 KB)

Event Timeline