Show deleted emails pending server ack in grey

TODO: Don't let the user select or interact with deleted messages
This commit is contained in:
Drew DeVault 2019-03-30 10:40:55 -04:00
parent 77ede6eb5a
commit 4465646fed
2 changed files with 18 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
) )
type MessageStore struct { type MessageStore struct {
Deleted map[uint32]interface{}
DirInfo types.DirectoryInfo DirInfo types.DirectoryInfo
Messages map[uint32]*types.MessageInfo Messages map[uint32]*types.MessageInfo
// Ordered list of known UIDs // Ordered list of known UIDs
@ -27,6 +28,7 @@ func NewMessageStore(worker *types.Worker,
dirInfo *types.DirectoryInfo) *MessageStore { dirInfo *types.DirectoryInfo) *MessageStore {
return &MessageStore{ return &MessageStore{
Deleted: make(map[uint32]interface{}),
DirInfo: *dirInfo, DirInfo: *dirInfo,
bodyCallbacks: make(map[uint32][]func(*mail.Message)), bodyCallbacks: make(map[uint32][]func(*mail.Message)),
@ -142,6 +144,9 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
for _, uid := range msg.Uids { for _, uid := range msg.Uids {
toDelete[uid] = nil toDelete[uid] = nil
delete(store.Messages, uid) delete(store.Messages, uid)
if _, ok := store.Deleted[uid]; ok {
delete(store.Deleted, uid)
}
} }
uids := make([]uint32, len(store.Uids)-len(msg.Uids)) uids := make([]uint32, len(store.Uids)-len(msg.Uids))
j := 0 j := 0
@ -154,8 +159,8 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
store.Uids = uids store.Uids = uids
update = true update = true
} }
if update && store.onUpdate != nil { if update {
store.onUpdate(store) store.update()
} }
} }
@ -163,10 +168,18 @@ func (store *MessageStore) OnUpdate(fn func(store *MessageStore)) {
store.onUpdate = fn store.onUpdate = fn
} }
func (store *MessageStore) update() {
if store.onUpdate != nil {
store.onUpdate(store)
}
}
func (store *MessageStore) Delete(uids []uint32) { func (store *MessageStore) Delete(uids []uint32) {
var set imap.SeqSet var set imap.SeqSet
for _, uid := range uids { for _, uid := range uids {
set.AddNum(uid) set.AddNum(uid)
store.Deleted[uid] = nil
} }
store.worker.PostAction(&types.DeleteMessages{Uids: set}, nil) store.worker.PostAction(&types.DeleteMessages{Uids: set}, nil)
store.update()
} }

View File

@ -81,6 +81,9 @@ func (ml *MessageList) Draw(ctx *ui.Context) {
style = style.Background(tcell.ColorWhite). style = style.Background(tcell.ColorWhite).
Foreground(tcell.ColorBlack) Foreground(tcell.ColorBlack)
} }
if _, ok := ml.store.Deleted[msg.Uid]; ok {
style = style.Foreground(tcell.ColorGray)
}
ctx.Fill(0, row, ctx.Width(), 1, ' ', style) ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
ctx.Printf(0, row, style, "%s", msg.Envelope.Subject) ctx.Printf(0, row, style, "%s", msg.Envelope.Subject)