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