aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-07-14 20:37:30 +0200
committerRobin Jarry <robin@jarry.cc>2023-07-16 10:12:52 +0200
commitc2bcc4bde8b8266d63d447bbfa46acc528ad7dfd (patch)
tree58411ebcb31c447a2016c3506b98068f92470e5c
parent058eb32c46472554117c5e9d022ff98c617eb99f (diff)
downloadaerc-c2bcc4bde8b8266d63d447bbfa46acc528ad7dfd.tar.gz
aerc-c2bcc4bde8b8266d63d447bbfa46acc528ad7dfd.zip
store: implement thread folding
Implement thread folding on the message store level. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc> Tested-by: inwit <inwit@sindominio.net>
-rw-r--r--lib/msgstore.go32
-rw-r--r--lib/threadbuilder.go8
2 files changed, 39 insertions, 1 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index c6ff5eb2..7c6f91c5 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -478,6 +478,38 @@ func (store *MessageStore) SelectedThread() (*types.Thread, error) {
return store.Thread(store.SelectedUid())
}
+func (store *MessageStore) Fold(uid uint32) error {
+ return store.doThreadFolding(uid, true)
+}
+
+func (store *MessageStore) Unfold(uid uint32) error {
+ return store.doThreadFolding(uid, false)
+}
+
+func (store *MessageStore) doThreadFolding(uid uint32, hidden bool) error {
+ thread, err := store.Thread(uid)
+ if err != nil {
+ return err
+ }
+ err = thread.Walk(func(t *types.Thread, _ int, __ error) error {
+ if t.Uid != uid {
+ t.Hidden = hidden
+ }
+ return nil
+ })
+ if err != nil {
+ return err
+ }
+ if store.builder == nil {
+ return errors.New("No thread builder available")
+ }
+ store.Select(uid)
+ store.threadsMutex.Lock()
+ store.builder.RebuildUids(store.threads, store.ReverseThreadOrder())
+ store.threadsMutex.Unlock()
+ return nil
+}
+
func (store *MessageStore) Delete(uids []uint32,
cb func(msg types.WorkerMessage),
) {
diff --git a/lib/threadbuilder.go b/lib/threadbuilder.go
index 793034df..1f2d72c6 100644
--- a/lib/threadbuilder.go
+++ b/lib/threadbuilder.go
@@ -198,11 +198,17 @@ func (builder *ThreadBuilder) RebuildUids(threads []*types.Thread, inverse bool)
var threaduids []uint32
_ = iterT.Value().(*types.Thread).Walk(
func(t *types.Thread, level int, currentErr error) error {
+ stored, ok := builder.threadMap[t.Uid]
+ if ok {
+ // make this info persistent
+ t.Hidden = stored.Hidden
+ t.Deleted = stored.Deleted
+ }
+ builder.threadMap[t.Uid] = t
if t.Deleted || t.Hidden {
return nil
}
threaduids = append(threaduids, t.Uid)
- builder.threadMap[t.Uid] = t
return nil
})
if inverse {