aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/msgstore.go24
-rw-r--r--worker/imap/open.go3
-rw-r--r--worker/types/thread.go15
3 files changed, 42 insertions, 0 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index e86dc56..2adefda 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -158,6 +158,18 @@ func merge(to *models.MessageInfo, from *models.MessageInfo) {
}
}
+func (store *MessageStore) removeThread(threads []*types.Thread, needle *types.Thread) []*types.Thread {
+ var r []*types.Thread
+ for i, thread := range threads {
+ if thread.Uid == needle.Uid {
+ r = append(threads[:i], threads[i+1:]...)
+ r = append(r, needle.Children...)
+ break
+ }
+ }
+ return r
+}
+
func (store *MessageStore) Update(msg types.WorkerMessage) {
update := false
directoryChange := false
@@ -251,6 +263,18 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
toDelete[uid] = nil
delete(store.Messages, uid)
delete(store.Deleted, uid)
+ if store.thread {
+ for _, thread := range store.Threads {
+ if needle := thread.Find(uid); needle != nil {
+ if needle.Parent == nil {
+ store.Threads = store.removeThread(store.Threads, needle)
+ } else {
+ needle.Parent.Children = store.removeThread(needle.Parent.Children, needle)
+ }
+ break
+ }
+ }
+ }
}
uids := make([]uint32, len(store.uids)-len(msg.Uids))
j := 0
diff --git a/worker/imap/open.go b/worker/imap/open.go
index bdb794b..78bcbb4 100644
--- a/worker/imap/open.go
+++ b/worker/imap/open.go
@@ -89,6 +89,9 @@ func convertThreads(threads []*sortthread.Thread) ([]*types.Thread, int) {
Uid: t.Id,
Children: children,
}
+ for _, child := range children {
+ child.Parent = conv[i]
+ }
count += childCount + 1
}
return conv, count
diff --git a/worker/types/thread.go b/worker/types/thread.go
index a51a5c4..4a97ef6 100644
--- a/worker/types/thread.go
+++ b/worker/types/thread.go
@@ -3,6 +3,21 @@ package types
type Thread struct {
Uid uint32
Children []*Thread
+ Parent *Thread
+}
+
+func (t *Thread) Find(uid uint32) *Thread {
+ if t.Uid == uid {
+ return t
+ }
+
+ for _, child := range t.Children {
+ if needle := child.Find(uid); needle != nil {
+ return needle
+ }
+ }
+
+ return nil
}
func (t *Thread) FormatThread(cb func(*Thread, []rune) bool) {