diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-07-23 21:03:45 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-07-24 23:05:11 +0200 |
commit | 80f8bab6cf01fb3bb2d1c7e8598d67f517617954 (patch) | |
tree | 1a47f800e5cda12f596357690afc08ba176272cf /commands/msg | |
parent | 0f86666f52620051aaf10cc85c4cacc20af383cb (diff) | |
download | aerc-80f8bab6cf01fb3bb2d1c7e8598d67f517617954.tar.gz |
delete: move tab replace logic into Done callback
Move tab replacement logic for next-message-on-delete into the
callback. This also moves the Invalidate() call into the callback, and
should make imap deletion UI work more reliably - there is a race
condition between the worker and the UI in displaying deleted messages.
This should resolve the race condition, and also only remove the MsgView
tab if the message is actually deleted.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/msg')
-rw-r--r-- | commands/msg/delete.go | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/commands/msg/delete.go b/commands/msg/delete.go index d26169f9..7b56a55d 100644 --- a/commands/msg/delete.go +++ b/commands/msg/delete.go @@ -42,10 +42,35 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error { if err != nil { return err } + //caution, can be nil + next := findNextNonDeleted(uids, store) store.Delete(uids, func(msg types.WorkerMessage) { switch msg := msg.(type) { case *types.Done: aerc.PushStatus("Messages deleted.", 10*time.Second) + mv, isMsgView := h.msgProvider.(*widgets.MessageViewer) + if isMsgView { + if !aerc.Config().Ui.NextMessageOnDelete { + aerc.RemoveTab(h.msgProvider) + } else { + // no more messages in the list + if next == nil { + aerc.RemoveTab(h.msgProvider) + acct.Messages().Invalidate() + return + } + lib.NewMessageStoreView(next, store, aerc.Crypto, aerc.DecryptKeys, + func(view lib.MessageView, err error) { + if err != nil { + aerc.PushError(err.Error()) + return + } + nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view) + aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject) + }) + } + } + acct.Messages().Invalidate() case *types.Error: aerc.PushError(msg.Error.Error()) case *types.Unsupported: @@ -53,33 +78,6 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error { aerc.PushError(" error, unsupported for this worker") } }) - - //caution, can be nil - next := findNextNonDeleted(uids, store) - - mv, isMsgView := h.msgProvider.(*widgets.MessageViewer) - if isMsgView { - if !aerc.Config().Ui.NextMessageOnDelete { - aerc.RemoveTab(h.msgProvider) - } else { - // no more messages in the list - if next == nil { - aerc.RemoveTab(h.msgProvider) - acct.Messages().Invalidate() - return nil - } - lib.NewMessageStoreView(next, store, aerc.Crypto, aerc.DecryptKeys, - func(view lib.MessageView, err error) { - if err != nil { - aerc.PushError(err.Error()) - return - } - nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view) - aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject) - }) - } - } - acct.Messages().Invalidate() return nil } |