Page MenuHomePhorge

D125.1732209838.diff
No OneTemporary

Size
8 KB
Referenced Files
None
Subscribers
None

D125.1732209838.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(currentEvent.eventId || currentEvent.txnId, currentEvent.isLocalEcho);
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(eventIdOrTxnId: string, isLocalEcho: bool)
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: (eventIdOrTxnId, isLocalEcho) => {
+ confirmDeletionPopupComp.createObject(Overlay.overlay, { eventIdOrTxnId, isLocalEcho }).open()
+ }
+
property var pinEventPopupComp: Component {
Kazv.ConfirmationOverlay {
objectName: 'pinEventPopup'
@@ -99,6 +125,36 @@
}
}
+ property var confirmDeletionPopupComp: Component {
+ Kazv.ConfirmationOverlay {
+ objectName: 'confirmDeletionPopup'
+ property var eventIdOrTxnId
+ property var isLocalEcho
+ 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: {
+ console.log(eventIdOrTxnId);
+ if (isLocalEcho) {
+ deleteLocalEcho.txnId = eventIdOrTxnId;
+ deleteLocalEcho.call();
+ } else {
+ deleteEvent.eventId = eventIdOrTxnId;
+ deleteEvent.call();
+ }
+ }
+
+ EventViewWrapper {
+ id: eventView
+ Layout.fillWidth: true
+ event: room.messageById(eventIdOrTxnId)
+ 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: [],
@@ -497,11 +498,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('$2', false);
+ 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], ['$2']);
+ 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('$2', true);
+ 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], ['$2']);
+ 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
Thu, Nov 21, 9:23 AM (6 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38681
Default Alt Text
D125.1732209838.diff (8 KB)

Event Timeline