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:
parent
0f86666f52
commit
80f8bab6cf
1 changed files with 25 additions and 27 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue