Page MenuHomePhorge

D125.1732288584.diff
No OneTemporary

Size
9 KB
Referenced Files
None
Subscribers
None

D125.1732288584.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(event.isLocalEcho ? event.txnId : event.eventId, event.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,35 @@
}
}
+ property var confirmDeletionPopupComp: Component {
+ Kazv.ConfirmationOverlay {
+ objectName: 'confirmDeletionPopup'
+ property string eventIdOrTxnId
+ property bool 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: {
+ if (isLocalEcho) {
+ deleteLocalEcho.txnId = eventIdOrTxnId;
+ deleteLocalEcho.call();
+ } else {
+ deleteEvent.eventId = eventIdOrTxnId;
+ deleteEvent.call();
+ }
+ }
+
+ EventViewWrapper {
+ id: eventView
+ Layout.fillWidth: true
+ event: isLocalEcho ? room.localEchoById(eventIdOrTxnId) : 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
@@ -381,3 +381,8 @@
emoji-objects = 物体
emoji-symbols = 符号
emoji-flags = 旗帜
+
+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
@@ -409,3 +409,8 @@
emoji-objects = Objects
emoji-symbols = Symbols
emoji-flags = Flags
+
+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/matrix-room.hpp b/src/matrix-room.hpp
--- a/src/matrix-room.hpp
+++ b/src/matrix-room.hpp
@@ -79,6 +79,8 @@
Q_INVOKABLE MatrixEvent *messageById(QString eventId) const;
+ Q_INVOKABLE MatrixEvent *localEchoById(QString txnId) const;
+
Q_INVOKABLE void sendMessage(const QJsonObject &eventJson, const QString &relType, const QString &relatedTo) const;
Q_INVOKABLE void sendTextMessage(QString text, const QString &relType, QString relatedTo) const;
diff --git a/src/matrix-room.cpp b/src/matrix-room.cpp
--- a/src/matrix-room.cpp
+++ b/src/matrix-room.cpp
@@ -404,6 +404,15 @@
);
}
+MatrixEvent *MatrixRoom::localEchoById(QString txnId) const
+{
+ return new MatrixEvent(
+ m_room.localEcho(lager::make_constant(txnId.toStdString()))
+ .map([](const auto &e) -> std::variant<Kazv::Event, Kazv::LocalEchoDesc> { return e; }),
+ m_room
+ );
+}
+
MatrixRoomMemberListModel *MatrixRoom::typingUsers() const
{
return new MatrixRoomMemberListModel(
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: [],
@@ -336,6 +337,7 @@
id: eventViewFailed
event: item.failedLocalEcho
sender: item.sender
+ property int index: 0
}
Kazv.EventView {
@@ -527,11 +529,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,9 +58,14 @@
property var room: ({
pinEvents: mockHelper.promise(),
unpinEvents: mockHelper.promise(),
+ redactEvent: mockHelper.promise(),
+ removeLocalEcho: mockHelper.promise(),
messageById(id) {
return { eventId: id };
},
+ localEchoById(id) {
+ return { txnId: id };
+ }
})
property var showPassiveNotification: mockHelper.noop()
@@ -166,5 +171,32 @@
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("some-event-id", 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], ['some-eventId']);
+ 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("some-txnId", 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], ['some-txnId']);
+ tryVerify(() => !popup.opened);
+ tryVerify(() => !findChild(Overlay.overlay, 'confirmDeletionPopup'));
+ }
}
}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 7:16 AM (5 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38892
Default Alt Text
D125.1732288584.diff (9 KB)

Event Timeline