aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msg
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-08-08 22:21:41 +0200
committerRobin Jarry <robin@jarry.cc>2022-08-22 09:30:37 +0200
commitcfc19a7ec22a1c60f79427ddbabdf437705efbab (patch)
treefbc4d54f9edb082ff87c84f864df17514c8e34da /commands/msg
parentee961d3b1d5ef412b3daf0ef0b8c18ac8957b365 (diff)
downloadaerc-cfc19a7ec22a1c60f79427ddbabdf437705efbab.tar.gz
store: extract marking behavior and add tests
Separate the marking functions from the message store and extract the marking behavior into its own class with tests. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/msg')
-rw-r--r--commands/msg/archive.go5
-rw-r--r--commands/msg/copy.go2
-rw-r--r--commands/msg/delete.go7
-rw-r--r--commands/msg/mark.go15
-rw-r--r--commands/msg/modify-labels.go2
-rw-r--r--commands/msg/move.go5
-rw-r--r--commands/msg/pipe.go2
-rw-r--r--commands/msg/read.go2
8 files changed, 22 insertions, 18 deletions
diff --git a/commands/msg/archive.go b/commands/msg/archive.go
index b8d8ff6d..f359f43b 100644
--- a/commands/msg/archive.go
+++ b/commands/msg/archive.go
@@ -57,7 +57,8 @@ func (Archive) Execute(aerc *widgets.Aerc, args []string) error {
for _, msg := range msgs {
uids = append(uids, msg.Uid)
}
- store.ClearVisualMark()
+ marker := store.Marker()
+ marker.ClearVisualMark()
findNextNonDeleted(uids, store)
var uidMap map[string][]uint32
@@ -95,7 +96,7 @@ func (Archive) Execute(aerc *widgets.Aerc, args []string) error {
aerc.PushError(msg.Error.Error())
success = false
wg.Done()
- store.Remark()
+ marker.Remark()
}
})
}
diff --git a/commands/msg/copy.go b/commands/msg/copy.go
index 6a106cf8..7118e4f8 100644
--- a/commands/msg/copy.go
+++ b/commands/msg/copy.go
@@ -56,7 +56,7 @@ func (Copy) Execute(aerc *widgets.Aerc, args []string) error {
switch msg := msg.(type) {
case *types.Done:
aerc.PushStatus("Messages copied.", 10*time.Second)
- store.ClearVisualMark()
+ store.Marker().ClearVisualMark()
case *types.Error:
aerc.PushError(msg.Error.Error())
}
diff --git a/commands/msg/delete.go b/commands/msg/delete.go
index ceb570b3..9db850ec 100644
--- a/commands/msg/delete.go
+++ b/commands/msg/delete.go
@@ -43,9 +43,10 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
return err
}
sel := store.Selected()
+ marker := store.Marker()
+ marker.ClearVisualMark()
// caution, can be nil
next := findNextNonDeleted(uids, store)
- store.ClearVisualMark()
store.Delete(uids, func(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
@@ -80,11 +81,11 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
}
}
case *types.Error:
- store.Remark()
+ marker.Remark()
store.Select(sel.Uid)
aerc.PushError(msg.Error.Error())
case *types.Unsupported:
- store.Remark()
+ marker.Remark()
store.Select(sel.Uid)
// notmuch doesn't support it, we want the user to know
aerc.PushError(" error, unsupported for this worker")
diff --git a/commands/msg/mark.go b/commands/msg/mark.go
index e15a9f6e..13d6c928 100644
--- a/commands/msg/mark.go
+++ b/commands/msg/mark.go
@@ -31,6 +31,7 @@ func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
if err != nil {
return err
}
+ marker := store.Marker()
opts, _, err := getopt.Getopts(args, "atv")
if err != nil {
return err
@@ -57,9 +58,9 @@ func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
var modFunc func(uint32)
if toggle {
- modFunc = store.ToggleMark
+ modFunc = marker.ToggleMark
} else {
- modFunc = store.Mark
+ modFunc = marker.Mark
}
switch {
case all:
@@ -69,7 +70,7 @@ func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
}
return nil
case visual:
- store.ToggleVisualMark()
+ marker.ToggleVisualMark()
return nil
default:
modFunc(selected.Uid)
@@ -85,21 +86,21 @@ func (Mark) Execute(aerc *widgets.Aerc, args []string) error {
case all && toggle:
uids := store.Uids()
for _, uid := range uids {
- store.ToggleMark(uid)
+ marker.ToggleMark(uid)
}
return nil
case all && !toggle:
- store.ClearVisualMark()
+ marker.ClearVisualMark()
return nil
default:
- store.Unmark(selected.Uid)
+ marker.Unmark(selected.Uid)
return nil
}
case "remark":
if all || visual || toggle {
return fmt.Errorf("Usage: :remark")
}
- store.Remark()
+ marker.Remark()
return nil
}
return nil // never reached
diff --git a/commands/msg/modify-labels.go b/commands/msg/modify-labels.go
index 655004cf..d0a5d6fa 100644
--- a/commands/msg/modify-labels.go
+++ b/commands/msg/modify-labels.go
@@ -57,7 +57,7 @@ func (ModifyLabels) Execute(aerc *widgets.Aerc, args []string) error {
switch msg := msg.(type) {
case *types.Done:
aerc.PushStatus("labels updated", 10*time.Second)
- store.ClearVisualMark()
+ store.Marker().ClearVisualMark()
case *types.Error:
aerc.PushError(msg.Error.Error())
}
diff --git a/commands/msg/move.go b/commands/msg/move.go
index 6eca6675..13b1fb7b 100644
--- a/commands/msg/move.go
+++ b/commands/msg/move.go
@@ -54,7 +54,8 @@ func (Move) Execute(aerc *widgets.Aerc, args []string) error {
if isMsgView {
aerc.RemoveTab(h.msgProvider)
}
- store.ClearVisualMark()
+ marker := store.Marker()
+ marker.ClearVisualMark()
findNextNonDeleted(uids, store)
joinedArgs := strings.Join(args[optind:], " ")
store.Move(uids, joinedArgs, createParents, func(
@@ -64,7 +65,7 @@ func (Move) Execute(aerc *widgets.Aerc, args []string) error {
case *types.Done:
aerc.PushStatus("Message moved to "+joinedArgs, 10*time.Second)
case *types.Error:
- store.Remark()
+ marker.Remark()
aerc.PushError(msg.Error.Error())
}
})
diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go
index 7a2489a2..29d63baf 100644
--- a/commands/msg/pipe.go
+++ b/commands/msg/pipe.go
@@ -218,7 +218,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
}
})
}
- provider.Store().ClearVisualMark()
+ provider.Store().Marker().ClearVisualMark()
return nil
}
diff --git a/commands/msg/read.go b/commands/msg/read.go
index e4d091f7..957b7d77 100644
--- a/commands/msg/read.go
+++ b/commands/msg/read.go
@@ -175,7 +175,7 @@ func (FlagMsg) Execute(aerc *widgets.Aerc, args []string) error {
wg.Wait()
if success {
aerc.PushStatus(actionName+" flag '"+flagName+"' successful", 10*time.Second)
- store.ClearVisualMark()
+ store.Marker().ClearVisualMark()
}
}()