~rjarry/aerc-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
4 4

[PATCH aerc] app: update folder counters upon message deletion

Details
Message ID
<174212300329.24407.9273795512185958916-0@git.sr.ht>
Sender timestamp
1742126006
DKIM signature
missing
Download raw message
Patch: +16 -7
From: Simon Martin <simon@nasilyan.com>

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>
---
 app/account.go | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/app/account.go b/app/account.go
index 262d5f38..f40c1b75 100644
--- a/app/account.go
+++ b/app/account.go
@@ -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)
		}
	}
}
-- 
2.45.3

[aerc/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<D8HN41Y69JXG.3GHL4ACVT92V9@fra01>
In-Reply-To
<174212300329.24407.9273795512185958916-0@git.sr.ht> (view parent)
Sender timestamp
1742123140
DKIM signature
missing
Download raw message
aerc/patches: SUCCESS in 2m14s

[app: update folder counters upon message deletion][0] from [~simartin][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/58131
[1]: simartin@git.sr.ht

✓ #1450659 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/1450659
✓ #1450658 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1450658
Details
Message ID
<D8HNIFYBFGUQ.1LV9XLN0S3N7O@sindominio.net>
In-Reply-To
<174212300329.24407.9273795512185958916-0@git.sr.ht> (view parent)
Sender timestamp
1742127867
DKIM signature
pass
Download raw message
This has been biting me forever and it's now solved! Thanks, Simon! 

Tested-by: inwit <inwit@sindominio.net>
Details
Message ID
<010201959f040482-9f7e4f1e-af39-469a-a324-bd8411b4db04-000000@eu-west-1.amazonses.com>
In-Reply-To
<D8HNIFYBFGUQ.1LV9XLN0S3N7O@sindominio.net> (view parent)
Sender timestamp
1742129595
DKIM signature
pass
Download raw message
Hi inwit,

On Sun Mar 16, 2025 at 12:24 PM CET, inwit wrote:
> This has been biting me forever and it's now solved! Thanks, Simon! 
Cool, glad that you like it.

There's another issue in this area, when moving an unread message to
another folder that uses folder mapping: the unread count in not
properly incremented in the destination folder (it works fine without
folder mapping). I will take care of this next :-)

> Tested-by: inwit <inwit@sindominio.net>
Thanks!

Simon

Applied: [PATCH aerc] app: update folder counters upon message deletion

Details
Message ID
<174246197683.204236.3200291653150555068@ringo>
In-Reply-To
<174212300329.24407.9273795512185958916-0@git.sr.ht> (view parent)
Sender timestamp
1742465576
DKIM signature
pass
Download raw message
~simartin <simartin@git.sr.ht> wrote:
> From: Simon Martin <simon@nasilyan.com>
>
> 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>
> ---

Acked-by: Robin Jarry <robin@jarry.cc>
Tested-by: Inwit <inwit@sindominio.net>

Applied, thanks.

To git@git.sr.ht:~rjarry/aerc
   46294ba5f795..b099981adbcf  master -> master
Reply to thread Export thread (mbox)