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>
This commit is contained in:
Tim Culverhouse 2022-07-23 21:03:45 -05:00 committed by Robin Jarry
parent 0f86666f52
commit 80f8bab6cf

View file

@ -42,21 +42,12 @@ 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)
case *types.Error:
aerc.PushError(msg.Error.Error())
case *types.Unsupported:
// notmuch doesn't support it, we want the user to know
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 {
@ -66,7 +57,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
if next == nil {
aerc.RemoveTab(h.msgProvider)
acct.Messages().Invalidate()
return nil
return
}
lib.NewMessageStoreView(next, store, aerc.Crypto, aerc.DecryptKeys,
func(view lib.MessageView, err error) {
@ -80,6 +71,13 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
}
}
acct.Messages().Invalidate()
case *types.Error:
aerc.PushError(msg.Error.Error())
case *types.Unsupported:
// notmuch doesn't support it, we want the user to know
aerc.PushError(" error, unsupported for this worker")
}
})
return nil
}