aerc/commands/msg/utils.go

51 lines
1.1 KiB
Go
Raw Permalink Normal View History

2019-12-18 05:34:00 +00:00
package msg
import (
"errors"
"git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/widgets"
2019-12-18 05:34:00 +00:00
)
type helper struct {
msgProvider widgets.ProvidesMessages
}
func newHelper(aerc *widgets.Aerc) *helper {
return &helper{aerc.SelectedTabContent().(widgets.ProvidesMessages)}
2019-12-18 05:34:00 +00:00
}
func (h *helper) markedOrSelectedUids() ([]uint32, error) {
return commands.MarkedOrSelected(h.msgProvider)
2019-12-18 05:34:00 +00:00
}
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)
2019-12-18 05:34:00 +00:00
}