diff options
Diffstat (limited to 'lib/msgstore.go')
-rw-r--r-- | lib/msgstore.go | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go index d745093..6830f64 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -1,6 +1,8 @@ package lib import ( + "fmt" + "github.com/emersion/go-imap" "git.sr.ht/~sircmpwn/aerc2/worker/types" @@ -53,7 +55,6 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { case *types.DirectoryInfo: store.DirInfo = *msg update = true - break case *types.DirectoryContents: newMap := make(map[uint32]*types.MessageInfo) for _, uid := range msg.Uids { @@ -66,7 +67,6 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { store.Messages = newMap store.Uids = msg.Uids update = true - break case *types.MessageInfo: // TODO: merge message info into existing record, if applicable store.Messages[msg.Uid] = msg @@ -74,7 +74,22 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { delete(store.pendingHeaders, msg.Uid) } update = true - break + case *types.MessagesDeleted: + toDelete := make(map[uint32]interface{}) + for _, uid := range msg.Uids { + toDelete[uid] = nil + delete(store.Messages, uid) + } + uids := make([]uint32, len(store.Uids)-len(msg.Uids)) + j := 0 + for i, uid := range store.Uids { + if _, deleted := toDelete[uid]; !deleted { + uids[j] = store.Uids[i] + j += 1 + } + } + store.Uids = uids + update = true } if update && store.onUpdate != nil { store.onUpdate(store) @@ -84,3 +99,11 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { func (store *MessageStore) OnUpdate(fn func(store *MessageStore)) { store.onUpdate = fn } + +func (store *MessageStore) Delete(uids []uint32) { + var set imap.SeqSet + for _, uid := range uids { + set.AddNum(uid) + } + store.worker.PostAction(&types.DeleteMessages{Uids: set}, nil) +} |