From 939000ccf2c3e54d1d50d3ae3f5b4e06a3fa3b69 Mon Sep 17 00:00:00 2001 From: Bence Ferdinandy Date: Wed, 10 Apr 2024 20:08:01 +0200 Subject: hooks: add flag-changed Add the flag-changed hook. References: https://todo.sr.ht/~rjarry/aerc/136 Changelog-added: New `flag-changed` hook. Signed-off-by: Bence Ferdinandy Acked-by: Robin Jarry --- lib/hooks/flag-changed.go | 27 +++++++++++++++++++++++++++ lib/msgstore.go | 23 ++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 lib/hooks/flag-changed.go (limited to 'lib') diff --git a/lib/hooks/flag-changed.go b/lib/hooks/flag-changed.go new file mode 100644 index 00000000..aaeff014 --- /dev/null +++ b/lib/hooks/flag-changed.go @@ -0,0 +1,27 @@ +package hooks + +import ( + "fmt" + + "git.sr.ht/~rjarry/aerc/config" +) + +type FlagChanged struct { + Account string + Folder string + FlagName string +} + +func (m *FlagChanged) Cmd() string { + return config.Hooks.FlagChanged +} + +func (m *FlagChanged) Env() []string { + env := []string{ + fmt.Sprintf("AERC_ACCOUNT=%s", m.Account), + fmt.Sprintf("AERC_FOLDER=%s", m.Folder), + fmt.Sprintf("AERC_FLAG=%s", m.FlagName), + } + + return env +} diff --git a/lib/msgstore.go b/lib/msgstore.go index a906d0cc..f1399e4e 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -71,6 +71,7 @@ type MessageStore struct { triggerMailDeleted func() triggerMailAdded func(string) triggerTagModified func([]string, []string) + triggerFlagChanged func(string) threadBuilderDebounce *time.Timer threadBuilderDelay time.Duration @@ -92,6 +93,7 @@ func NewMessageStore(worker *types.Worker, triggerNewEmail func(*models.MessageInfo), triggerDirectoryChange func(), triggerMailDeleted func(), triggerMailAdded func(string), triggerTagModified func([]string, []string), + triggerFlagChanged func(string), onSelect func(*models.MessageInfo), threadContext bool, ) *MessageStore { @@ -132,6 +134,7 @@ func NewMessageStore(worker *types.Worker, triggerMailDeleted: triggerMailDeleted, triggerMailAdded: triggerMailAdded, triggerTagModified: triggerTagModified, + triggerFlagChanged: triggerFlagChanged, threadBuilderDelay: clientThreadsDelay, @@ -685,7 +688,25 @@ func (store *MessageStore) Flag(uids []uint32, flags models.Flags, Enable: enable, Flags: flags, Uids: uids, - }, cb) + }, func(msg types.WorkerMessage) { + var flagName string + switch flags { + case models.SeenFlag: + flagName = "seen" + case models.AnsweredFlag: + flagName = "answered" + case models.FlaggedFlag: + flagName = "flagged" + case models.DraftFlag: + flagName = "draft" + } + if _, ok := msg.(*types.Done); ok { + store.triggerFlagChanged(flagName) + } + if cb != nil { + cb(msg) + } + }) } func (store *MessageStore) Answered(uids []uint32, answered bool, -- cgit