aerc/commands/msg/utils.go
Reto Brunner ea2646fc03 Change MarkedMessages to return uids
Especially if one tries to interact with all marked messages there could be
the case that not all headers are fetched yet, hence the messageInfo is still nil.

This segfaults a lot of commands which in principle only need the uid to complete.

If we switch to uids, this issue can be alleviated for those commands.
2020-05-11 09:47:34 -04:00

51 lines
1.1 KiB
Go

package msg
import (
"errors"
"git.sr.ht/~sircmpwn/aerc/commands"
"git.sr.ht/~sircmpwn/aerc/lib"
"git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets"
)
type helper struct {
msgProvider widgets.ProvidesMessages
}
func newHelper(aerc *widgets.Aerc) *helper {
return &helper{aerc.SelectedTab().(widgets.ProvidesMessages)}
}
func (h *helper) markedOrSelectedUids() ([]uint32, error) {
return commands.MarkedOrSelected(h.msgProvider)
}
func (h *helper) store() (*lib.MessageStore, error) {
store := h.msgProvider.Store()
if store == nil {
return nil, errors.New("Cannot perform action. Messages still loading")
}
return store, nil
}
func (h *helper) account() (*widgets.AccountView, error) {
acct := h.msgProvider.SelectedAccount()
if acct == nil {
return nil, errors.New("No account selected")
}
return acct, nil
}
func (h *helper) messages() ([]*models.MessageInfo, error) {
uid, err := commands.MarkedOrSelected(h.msgProvider)
if err != nil {
return nil, err
}
store, err := h.store()
if err != nil {
return nil, err
}
return commands.MsgInfoFromUids(store, uid)
}