diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-03-20 23:23:38 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-20 23:23:38 -0400 |
commit | 312a53e5ff721e0a29e34aaeceb0eece1203002d (patch) | |
tree | fb0c5f30d89f904d5fad4a900c910a1dd1d891be /lib | |
parent | f3d3e0ed4f5dbf36b7a7c9762e6297083843f127 (diff) |
Implement :delete-message
Diffstat (limited to 'lib')
-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) +} |