mirror of
https://git.sr.ht/~rjarry/aerc
synced 2026-03-02 18:23:33 +01:00
app: update folder counters upon message deletion
I noticed that when deleting an unread email from the current folder (or moving it to another folder), the "visual unread count" is not decremented (and later on I'm desperately looking for the mysterious unread mail that does not exist anymore :-)). This patch adds a parameter to AccountView.updateDirCounts stating whether the caller reacts to a deletion, and makes sure to call it when processing a MessagesDeleted message. Signed-off-by: Simon Martin <simon@nasilyan.com> Tested-by: Inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
committed by
Robin Jarry
parent
46294ba5f7
commit
b099981adb
@@ -470,15 +470,15 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
|
||||
}
|
||||
case *types.MessagesDeleted:
|
||||
if dir := acct.dirlist.SelectedDirectory(); dir != nil {
|
||||
dir.Exists -= len(msg.Uids)
|
||||
acct.updateDirCounts(dir.Name, msg.Uids, true)
|
||||
}
|
||||
if store, ok := acct.dirlist.SelectedMsgStore(); ok {
|
||||
store.Update(msg)
|
||||
}
|
||||
case *types.MessagesCopied:
|
||||
acct.updateDirCounts(msg.Destination, msg.Uids)
|
||||
acct.updateDirCounts(msg.Destination, msg.Uids, false)
|
||||
case *types.MessagesMoved:
|
||||
acct.updateDirCounts(msg.Destination, msg.Uids)
|
||||
acct.updateDirCounts(msg.Destination, msg.Uids, false)
|
||||
case *types.LabelList:
|
||||
acct.labels = msg.Labels
|
||||
case *types.ConnError:
|
||||
@@ -495,7 +495,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
|
||||
acct.setTitle()
|
||||
}
|
||||
|
||||
func (acct *AccountView) updateDirCounts(destination string, uids []models.UID) {
|
||||
func (acct *AccountView) updateDirCounts(destination string, uids []models.UID, deleted bool) {
|
||||
// Only update the destination destDir if it is initialized
|
||||
if destDir := acct.dirlist.Directory(destination); destDir != nil {
|
||||
var recent, unseen int
|
||||
@@ -511,20 +511,29 @@ func (acct *AccountView) updateDirCounts(destination string, uids []models.UID)
|
||||
accurate = false
|
||||
break
|
||||
}
|
||||
seen := msg.Flags.Has(models.SeenFlag)
|
||||
if msg.Flags.Has(models.RecentFlag) {
|
||||
recent++
|
||||
}
|
||||
seen := msg.Flags.Has(models.SeenFlag)
|
||||
if !seen {
|
||||
unseen++
|
||||
// If the message is unseen, the directory's current unseen
|
||||
// count is off by one and (1) too low if the message is new,
|
||||
// or (2) too high if the message has been deleted.
|
||||
if !deleted {
|
||||
unseen++
|
||||
} else {
|
||||
unseen--
|
||||
}
|
||||
}
|
||||
}
|
||||
if accurate {
|
||||
destDir.Recent += recent
|
||||
destDir.Unseen += unseen
|
||||
}
|
||||
if !deleted {
|
||||
destDir.Exists += len(uids)
|
||||
} else {
|
||||
destDir.Exists += len(uids)
|
||||
destDir.Exists -= len(uids)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user