From c6463ba48167aba07b3fd8bb707dbe60707e9426 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Wed, 19 Oct 2022 21:38:28 +0200 Subject: [PATCH] msgview: enable next/prev with unfetched headers Fix message view behavior for unfetched headers. When scrolling "over" the message list boundary, current behavior is to close the message viewer tab. Now, the headers will be fetched so that we can scroll through the messages uninterrupted. Fixes: https://todo.sr.ht/~rjarry/aerc/90 Signed-off-by: Koni Marti Acked-by: Robin Jarry --- commands/msgview/next.go | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/commands/msgview/next.go b/commands/msgview/next.go index 6341f93..5df7847 100644 --- a/commands/msgview/next.go +++ b/commands/msgview/next.go @@ -5,7 +5,9 @@ import ( "git.sr.ht/~rjarry/aerc/commands/account" "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" + "git.sr.ht/~rjarry/aerc/worker/types" ) type NextPrevMsg struct{} @@ -37,20 +39,30 @@ func (NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error { if err != nil { return err } - nextMsg := store.Selected() - if nextMsg == nil { - aerc.RemoveTab(mv) - return nil + executeNextPrev := func(nextMsg *models.MessageInfo) { + lib.NewMessageStoreView(nextMsg, mv.MessageView().SeenFlagSet(), + store, aerc.Crypto, aerc.DecryptKeys, + func(view lib.MessageView, err error) { + if err != nil { + aerc.PushError(err.Error()) + return + } + nextMv := widgets.NewMessageViewer(acct, + aerc.Config(), view) + aerc.ReplaceTab(mv, nextMv, + nextMsg.Envelope.Subject) + }) } - lib.NewMessageStoreView(nextMsg, mv.MessageView().SeenFlagSet(), - store, aerc.Crypto, aerc.DecryptKeys, - func(view lib.MessageView, err error) { - if err != nil { - aerc.PushError(err.Error()) - return - } - nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view) - aerc.ReplaceTab(mv, nextMv, nextMsg.Envelope.Subject) - }) + if nextMsg := store.Selected(); nextMsg != nil { + executeNextPrev(nextMsg) + } else { + store.FetchHeaders([]uint32{store.SelectedUid()}, + func(msg types.WorkerMessage) { + if m, ok := msg.(*types.MessageInfo); ok { + executeNextPrev(m.Info) + } + }) + } + return nil }