2019-12-18 06:34:00 +01:00
|
|
|
package msg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2022-08-08 22:21:43 +02:00
|
|
|
"time"
|
2019-12-18 06:34:00 +01:00
|
|
|
|
2021-11-05 10:19:46 +01:00
|
|
|
"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 06:34:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type helper struct {
|
|
|
|
msgProvider widgets.ProvidesMessages
|
2022-08-08 22:21:43 +02:00
|
|
|
statusInfo func(string)
|
2019-12-18 06:34:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func newHelper(aerc *widgets.Aerc) *helper {
|
2022-08-08 22:21:43 +02:00
|
|
|
return &helper{
|
|
|
|
msgProvider: aerc.SelectedTabContent().(widgets.ProvidesMessages),
|
|
|
|
statusInfo: func(s string) {
|
|
|
|
aerc.PushStatus(s, 10*time.Second)
|
|
|
|
},
|
|
|
|
}
|
2019-12-18 06:34:00 +01:00
|
|
|
}
|
|
|
|
|
2020-05-09 11:50:30 +02:00
|
|
|
func (h *helper) markedOrSelectedUids() ([]uint32, error) {
|
2020-05-09 11:50:31 +02:00
|
|
|
return commands.MarkedOrSelected(h.msgProvider)
|
2019-12-18 06:34:00 +01: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) {
|
2020-05-09 11:50:31 +02:00
|
|
|
uid, err := commands.MarkedOrSelected(h.msgProvider)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
store, err := h.store()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-08 22:21:43 +02:00
|
|
|
return commands.MsgInfoFromUids(store, uid, h.statusInfo)
|
2019-12-18 06:34:00 +01:00
|
|
|
}
|