aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-07-05 14:48:41 -0500
committerRobin Jarry <robin@jarry.cc>2022-07-10 21:15:12 +0200
commita953e4dbe914def4275a6ddfc16e3046804fe03e (patch)
tree1f13c056b0f80caf5f2d9ac00792839ed198f14d /lib
parentc2f4404fca15be37228545b1893f5fa335168337 (diff)
downloadaerc-a953e4dbe914def4275a6ddfc16e3046804fe03e.tar.gz
threading: refactor reselect logic
This patch refactors reselection of a message during certain operations (searching, filtering, clearing, deleting, moving, new message arrival). The addition of server-side filtering for threaded views broke the existing reselection logic. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r--lib/msgstore.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 2e773699..a54b20bb 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -21,6 +21,7 @@ type MessageStore struct {
Threads []*types.Thread
selected int
+ reselect *models.MessageInfo
bodyCallbacks map[uint32][]func(*types.FullMessage)
headerCallbacks map[uint32][]func(*types.MessageInfo)
@@ -196,6 +197,9 @@ func merge(to *models.MessageInfo, from *models.MessageInfo) {
func (store *MessageStore) Update(msg types.WorkerMessage) {
update := false
directoryChange := false
+ if store.reselect == nil {
+ store.SetReselect(store.Selected())
+ }
switch msg := msg.(type) {
case *types.DirectoryInfo:
store.DirInfo = *msg.Info
@@ -363,6 +367,7 @@ func (store *MessageStore) SetThreadedView(thread bool) {
if store.threadedView {
store.runThreadBuilder()
}
+ store.Reselect()
return
}
store.Sort(store.sortCriteria, nil)
@@ -508,11 +513,11 @@ func (store *MessageStore) Select(index int) {
store.updateVisual()
}
-func (store *MessageStore) Reselect(info *models.MessageInfo) {
- if info == nil {
+func (store *MessageStore) Reselect() {
+ if store.reselect == nil {
return
}
- uid := info.Uid
+ uid := store.reselect.Uid
newIdx := 0
for idx, uidStore := range store.Uids() {
if uidStore == uid {
@@ -520,9 +525,14 @@ func (store *MessageStore) Reselect(info *models.MessageInfo) {
break
}
}
+ store.reselect = nil
store.Select(newIdx)
}
+func (store *MessageStore) SetReselect(info *models.MessageInfo) {
+ store.reselect = info
+}
+
// Mark sets the marked state on a MessageInfo
func (store *MessageStore) Mark(uid uint32) {
if store.visualMarkMode {
@@ -718,11 +728,21 @@ func (store *MessageStore) SetFilter(args []string) {
}
func (store *MessageStore) ApplyClear() {
+ if store.reselect == nil {
+ store.SetReselect(store.Selected())
+ }
store.filter = []string{"filter"}
+ store.results = nil
if store.onFilterChange != nil {
store.onFilterChange(store)
}
- store.Sort(nil, nil)
+ cb := func(msg types.WorkerMessage) {
+ switch msg.(type) {
+ case *types.Done:
+ store.Reselect()
+ }
+ }
+ store.Sort(nil, cb)
}
func (store *MessageStore) nextPrevResult(delta int) {