diff options
author | Reto Brunner <reto@labrat.space> | 2019-12-18 06:34:00 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-12-21 09:27:50 -0500 |
commit | 881a9081a850f39294ed97c10a1a50f8d852c9a5 (patch) | |
tree | 1eeffb2dea2d4dadfa80c92e3e76f8df42dbda71 /commands/msg | |
parent | cf43066d5b8bbe991bef8280bbbeeb13059585b6 (diff) |
add command helpers
Diffstat (limited to 'commands/msg')
-rw-r--r-- | commands/msg/utils.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/commands/msg/utils.go b/commands/msg/utils.go new file mode 100644 index 0000000..30a4394 --- /dev/null +++ b/commands/msg/utils.go @@ -0,0 +1,55 @@ +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) uids() ([]uint32, error) { + msgs, err := commands.MarkedOrSelected(h.msgProvider) + if err != nil { + return nil, err + } + uids := commands.UidsFromMessageInfos(msgs) + return uids, nil +} + +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) { + return commands.MarkedOrSelected(h.msgProvider) +} + +func (h *helper) messageUids() ([]uint32, error) { + msgs, err := h.messages() + if err != nil { + return nil, err + } + return commands.UidsFromMessageInfos(msgs), nil +} |