2019-06-11 05:05:57 +00:00
|
|
|
package msgview
|
|
|
|
|
|
|
|
import (
|
2022-02-24 23:21:06 +00:00
|
|
|
"errors"
|
|
|
|
|
2021-11-05 09:19:46 +00:00
|
|
|
"git.sr.ht/~rjarry/aerc/commands/account"
|
|
|
|
"git.sr.ht/~rjarry/aerc/lib"
|
|
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
2019-06-11 05:05:57 +00:00
|
|
|
)
|
|
|
|
|
2019-06-27 17:33:11 +00:00
|
|
|
type NextPrevMsg struct{}
|
|
|
|
|
2019-06-11 05:05:57 +00:00
|
|
|
func init() {
|
2019-06-27 17:33:11 +00:00
|
|
|
register(NextPrevMsg{})
|
|
|
|
}
|
|
|
|
|
2019-09-03 19:34:03 +00:00
|
|
|
func (NextPrevMsg) Aliases() []string {
|
2019-06-27 17:33:11 +00:00
|
|
|
return []string{"next", "next-message", "prev", "prev-message"}
|
|
|
|
}
|
|
|
|
|
2019-09-03 19:34:03 +00:00
|
|
|
func (NextPrevMsg) Complete(aerc *widgets.Aerc, args []string) []string {
|
2019-06-27 17:33:11 +00:00
|
|
|
return nil
|
2019-06-11 05:05:57 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 19:34:03 +00:00
|
|
|
func (NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
|
2019-09-03 19:34:06 +00:00
|
|
|
n, pct, err := account.ParseNextPrevMessage(args)
|
2019-08-04 14:09:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-11 05:05:57 +00:00
|
|
|
mv, _ := aerc.SelectedTab().(*widgets.MessageViewer)
|
|
|
|
acct := mv.SelectedAccount()
|
2022-02-24 23:21:06 +00:00
|
|
|
if acct == nil {
|
|
|
|
return errors.New("No account selected")
|
|
|
|
}
|
2019-06-11 05:05:57 +00:00
|
|
|
store := mv.Store()
|
2019-08-04 14:09:48 +00:00
|
|
|
err = account.ExecuteNextPrevMessage(args, acct, pct, n)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2019-06-11 05:05:57 +00:00
|
|
|
}
|
|
|
|
nextMsg := store.Selected()
|
|
|
|
if nextMsg == nil {
|
|
|
|
aerc.RemoveTab(mv)
|
|
|
|
return nil
|
|
|
|
}
|
2022-04-25 13:30:43 +00:00
|
|
|
lib.NewMessageStoreView(nextMsg, store, aerc.Crypto, aerc.DecryptKeys,
|
2020-05-19 11:06:46 +00:00
|
|
|
func(view lib.MessageView, err error) {
|
|
|
|
if err != nil {
|
2020-05-28 14:32:42 +00:00
|
|
|
aerc.PushError(err.Error())
|
2020-05-19 11:06:46 +00:00
|
|
|
return
|
|
|
|
}
|
2020-03-03 21:20:07 +00:00
|
|
|
nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view)
|
|
|
|
aerc.ReplaceTab(mv, nextMv, nextMsg.Envelope.Subject)
|
|
|
|
})
|
2019-06-11 05:05:57 +00:00
|
|
|
return nil
|
|
|
|
}
|