summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-07-05 21:42:43 +0200
committerRobin Jarry <robin@jarry.cc>2022-07-10 20:39:42 +0200
commit4335eeceb39184165eef7b0fc608b5c563e62a72 (patch)
treeacd1894e21bc05df96c7e41528f3b497ffd5a22b
parent99b74dbcc98990a3732281f07a2238266f0916dc (diff)
downloadaerc-4335eeceb39184165eef7b0fc608b5c563e62a72.zip
recall: confirm deleting message when not sent
Ask for user confirmation when a recalled message is deleted after the composer is closed but the message has not been sent yet. The message will only be deleted automatically when the message is sent. This might prevent data loss since the recalled message is currently deleted either way. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--commands/msg/recall.go43
1 files changed, 34 insertions, 9 deletions
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index 443f8e4..8f21868 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -2,6 +2,7 @@ package msg
import (
"io"
+ "time"
"github.com/emersion/go-message"
_ "github.com/emersion/go-message/charset"
@@ -99,15 +100,39 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
return
}
- worker.PostAction(&types.DeleteMessages{
- Uids: uids,
- }, func(msg types.WorkerMessage) {
- switch msg := msg.(type) {
- case *types.Error:
- aerc.PushError(msg.Error.Error())
- composer.Close()
- }
- })
+ deleteMessage := func() {
+ worker.PostAction(&types.DeleteMessages{
+ Uids: uids,
+ }, func(msg types.WorkerMessage) {
+ switch msg := msg.(type) {
+ case *types.Done:
+ aerc.PushStatus("Recalled message deleted", 10*time.Second)
+ case *types.Error:
+ aerc.PushError(msg.Error.Error())
+ }
+ })
+ }
+
+ if composer.Sent() {
+ deleteMessage()
+ } else {
+ confirm := widgets.NewSelectorDialog(
+ "Delete recalled message?",
+ "If you proceed, the recalled message will be deleted.",
+ []string{"Cancel", "Proceed"}, 0, aerc.SelectedAccountUiConfig(),
+ func(option string, err error) {
+ aerc.CloseDialog()
+ switch option {
+ case "Proceed":
+ deleteMessage()
+ default:
+ }
+ return
+ },
+ )
+ aerc.AddDialog(confirm)
+ }
+
})
}