aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-06-20 11:07:06 -0500
committerRobin Jarry <robin@jarry.cc>2023-06-20 23:16:25 +0200
commit982ee4128c584759e518b6d541ca01cce6c5d547 (patch)
tree092a18234e6fc601e1af81e41aec0289d846479c
parente984db17e5459b58b566426eb84236bf1b1ee6aa (diff)
downloadaerc-982ee4128c584759e518b6d541ca01cce6c5d547.tar.gz
msgstore: pass context from dirlist to msgstore
Most, if not all, requests to the worker that may need cancellation are sent by the msgstore. These requests are typically only relevant when the msgstore is the selected one. Pass a context from the dirlister to the msgstore when it is selected. This context will be passed in future commits to worker requests. The context is cancelled when a new directory is selected. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--lib/msgstore.go8
-rw-r--r--widgets/dirlist.go41
2 files changed, 30 insertions, 19 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 98fb47b7..f7ffaa51 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -1,6 +1,7 @@
package lib
import (
+ "context"
"io"
"sync"
"time"
@@ -21,6 +22,9 @@ type MessageStore struct {
Messages map[uint32]*models.MessageInfo
Sorting bool
+ // ctx is given by the directory lister
+ ctx context.Context
+
// Ordered list of known UIDs
uids []uint32
threads []*types.Thread
@@ -118,6 +122,10 @@ func NewMessageStore(worker *types.Worker,
}
}
+func (store *MessageStore) SetContext(ctx context.Context) {
+ store.ctx = ctx
+}
+
func (store *MessageStore) FetchHeaders(uids []uint32,
cb func(types.WorkerMessage),
) {
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index a1d4eddb..3b5c2d91 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -52,15 +52,15 @@ type DirectoryLister interface {
type DirectoryList struct {
Scrollable
- acctConf *config.AccountConfig
- store *lib.DirStore
- dirs []string
- selecting string
- selected string
- spinner *Spinner
- worker *types.Worker
- skipSelect context.Context
- skipSelectCancel context.CancelFunc
+ acctConf *config.AccountConfig
+ store *lib.DirStore
+ dirs []string
+ selecting string
+ selected string
+ spinner *Spinner
+ worker *types.Worker
+ ctx context.Context
+ cancel context.CancelFunc
}
func NewDirectoryList(acctConf *config.AccountConfig,
@@ -69,11 +69,11 @@ func NewDirectoryList(acctConf *config.AccountConfig,
ctx, cancel := context.WithCancel(context.Background())
dirlist := &DirectoryList{
- acctConf: acctConf,
- store: lib.NewDirStore(),
- worker: worker,
- skipSelect: ctx,
- skipSelectCancel: cancel,
+ acctConf: acctConf,
+ store: lib.NewDirStore(),
+ worker: worker,
+ ctx: ctx,
+ cancel: cancel,
}
uiConf := dirlist.UiConfig("")
dirlist.spinner = NewSpinner(uiConf)
@@ -152,10 +152,8 @@ func (dirlist *DirectoryList) ExpandFolder() {
func (dirlist *DirectoryList) Select(name string) {
dirlist.selecting = name
- dirlist.skipSelectCancel()
- ctx, cancel := context.WithCancel(context.Background())
- dirlist.skipSelect = ctx
- dirlist.skipSelectCancel = cancel
+ dirlist.cancel()
+ dirlist.ctx, dirlist.cancel = context.WithCancel(context.Background())
delay := dirlist.UiConfig(name).DirListDelay
go func(ctx context.Context) {
@@ -186,6 +184,11 @@ func (dirlist *DirectoryList) Select(name string) {
sort.Strings(dirlist.dirs)
}
dirlist.sortDirsByFoldersSortConfig()
+ store, ok := dirlist.SelectedMsgStore()
+ if !ok {
+ return
+ }
+ store.SetContext(dirlist.ctx)
}
dirlist.Invalidate()
})
@@ -194,7 +197,7 @@ func (dirlist *DirectoryList) Select(name string) {
log.Tracef("dirlist: skip %s", name)
return
}
- }(ctx)
+ }(dirlist.ctx)
}
func (dirlist *DirectoryList) Selected() string {