aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBence Ferdinandy <bence@ferdinandy.com>2024-04-10 20:08:01 +0200
committerRobin Jarry <robin@jarry.cc>2024-04-14 11:51:00 +0200
commit939000ccf2c3e54d1d50d3ae3f5b4e06a3fa3b69 (patch)
treecec40ad16557021aabdb9a99fdda358a8101e4ec /lib
parentcee5d5a3f602e5db0ca3feb6e0754c1bb0059f36 (diff)
downloadaerc-939000ccf2c3e54d1d50d3ae3f5b4e06a3fa3b69.tar.gz
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 <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r--lib/hooks/flag-changed.go27
-rw-r--r--lib/msgstore.go23
2 files changed, 49 insertions, 1 deletions
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,