move: enable MoveMessages from msgstore

Enable the use of MoveMessages worker messages from the UI to the
backend. Completes implemention of MoveMessages for all supported
backends.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-08-16 16:23:41 -05:00 committed by Robin Jarry
parent af72ca3607
commit c98f704874
2 changed files with 50 additions and 44 deletions

View file

@ -476,7 +476,7 @@ func (store *MessageStore) Move(uids []uint32, dest string, createDest bool,
}, nil) // quiet doesn't return an error, don't want the done cb here
}
store.worker.PostAction(&types.CopyMessages{
store.worker.PostAction(&types.MoveMessages{
Destination: dest,
Uids: uids,
}, func(msg types.WorkerMessage) {
@ -485,7 +485,7 @@ func (store *MessageStore) Move(uids []uint32, dest string, createDest bool,
store.revertDeleted(uids)
cb(msg)
case *types.Done:
store.Delete(uids, cb)
cb(msg)
}
})
}

View file

@ -346,48 +346,9 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
store.Update(msg)
}
case *types.MessagesCopied:
// Only update the destination destStore if it is initialized
if destStore, ok := acct.dirlist.MsgStore(msg.Destination); ok {
var recent, unseen int
var accurate bool = true
for _, uid := range msg.Uids {
// Get the message from the originating store
msg, ok := acct.Store().Messages[uid]
if !ok {
continue
}
// If message that was not yet loaded is copied
if msg == nil {
accurate = false
break
}
seen := false
for _, flag := range msg.Flags {
if flag == models.SeenFlag {
seen = true
}
if flag == models.RecentFlag {
recent++
}
}
if !seen {
unseen++
}
}
if accurate {
destStore.DirInfo.Recent += recent
destStore.DirInfo.Unseen += unseen
destStore.DirInfo.Exists += len(msg.Uids)
// True. For imap, we don't have the message in the store until we
// Select so we need to rely on the math we just did for accurate
// counts
destStore.DirInfo.AccurateCounts = true
} else {
destStore.DirInfo.Exists += len(msg.Uids)
// False to trigger recount of recent/unseen
destStore.DirInfo.AccurateCounts = false
}
}
acct.updateDirCounts(msg.Destination, msg.Uids)
case *types.MessagesMoved:
acct.updateDirCounts(msg.Destination, msg.Uids)
case *types.LabelList:
acct.labels = msg.Labels
case *types.ConnError:
@ -403,6 +364,51 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
acct.UpdateStatus()
}
func (acct *AccountView) updateDirCounts(destination string, uids []uint32) {
// Only update the destination destStore if it is initialized
if destStore, ok := acct.dirlist.MsgStore(destination); ok {
var recent, unseen int
var accurate bool = true
for _, uid := range uids {
// Get the message from the originating store
msg, ok := acct.Store().Messages[uid]
if !ok {
continue
}
// If message that was not yet loaded is copied
if msg == nil {
accurate = false
break
}
seen := false
for _, flag := range msg.Flags {
if flag == models.SeenFlag {
seen = true
}
if flag == models.RecentFlag {
recent++
}
}
if !seen {
unseen++
}
}
if accurate {
destStore.DirInfo.Recent += recent
destStore.DirInfo.Unseen += unseen
destStore.DirInfo.Exists += len(uids)
// True. For imap, we don't have the message in the store until we
// Select so we need to rely on the math we just did for accurate
// counts
destStore.DirInfo.AccurateCounts = true
} else {
destStore.DirInfo.Exists += len(uids)
// False to trigger recount of recent/unseen
destStore.DirInfo.AccurateCounts = false
}
}
}
func (acct *AccountView) GetSortCriteria() []*types.SortCriterion {
if len(acct.UiConfig().Sort) == 0 {
return nil