2019-06-11 07:05:57 +02:00
|
|
|
package msgview
|
|
|
|
|
|
|
|
import (
|
2019-08-04 16:09:48 +02:00
|
|
|
"git.sr.ht/~sircmpwn/aerc/commands/account"
|
2020-03-03 22:20:07 +01:00
|
|
|
"git.sr.ht/~sircmpwn/aerc/lib"
|
2019-06-11 07:05:57 +02:00
|
|
|
"git.sr.ht/~sircmpwn/aerc/widgets"
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
}
|
2019-06-11 07:05:57 +02:00
|
|
|
mv, _ := aerc.SelectedTab().(*widgets.MessageViewer)
|
|
|
|
acct := mv.SelectedAccount()
|
|
|
|
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
|
|
|
|
}
|
2020-03-03 22:20:07 +01:00
|
|
|
lib.NewMessageStoreView(nextMsg, store, aerc.DecryptKeys,
|
2020-05-19 13:06:46 +02:00
|
|
|
func(view lib.MessageView, err error) {
|
|
|
|
if err != nil {
|
|
|
|
aerc.PushError(err.Error())
|
|
|
|
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
|
|
|
|
}
|