summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolai Dagestad <nicolai@dagestad.fr>2019-07-15 19:51:07 +0200
committerDrew DeVault <sir@cmpwn.com>2019-07-17 17:01:25 -0400
commita1763bf2079400693515772dcb2ad09c53f36e4e (patch)
tree0a75ad48bcfbc6f06d3f94cc23b3bb515c9d2620
parentdbd583c969fbc5f6565a1b6296e9e1a0f0b43967 (diff)
downloadaerc-a1763bf2079400693515772dcb2ad09c53f36e4e.zip
Add an option to toggle between read and unread
-rw-r--r--commands/msg/read.go32
-rw-r--r--doc/aerc.1.scd4
2 files changed, 33 insertions, 3 deletions
diff --git a/commands/msg/read.go b/commands/msg/read.go
index c6bd098..5dd02f8 100644
--- a/commands/msg/read.go
+++ b/commands/msg/read.go
@@ -4,8 +4,11 @@ import (
"errors"
"time"
+ "git.sr.ht/~sircmpwn/getopt"
+
"github.com/gdamore/tcell"
+ "git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets"
"git.sr.ht/~sircmpwn/aerc/worker/types"
)
@@ -25,8 +28,20 @@ func (_ Read) Complete(aerc *widgets.Aerc, args []string) []string {
}
func (_ Read) Execute(aerc *widgets.Aerc, args []string) error {
- if len(args) != 1 {
- return errors.New("Usage: " + args[0])
+ opts, optind, err := getopt.Getopts(args, "t")
+ if err != nil {
+ return err
+ }
+ if optind != len(args) {
+ return errors.New("Usage: " + args[0] + "[-t]")
+ }
+ var toggle bool
+
+ for _, opt := range opts {
+ switch opt.Option {
+ case 't':
+ toggle = true
+ }
}
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
@@ -38,7 +53,18 @@ func (_ Read) Execute(aerc *widgets.Aerc, args []string) error {
if err != nil {
return err
}
- store.Read([]uint32{msg.Uid}, args[0] == "read", func(
+ newReadState := true
+ if toggle {
+ newReadState = true
+ for _, flag := range msg.Flags {
+ if flag == models.SeenFlag {
+ newReadState = false
+ }
+ }
+ } else if args[0] == "read" {
+ newReadState = true
+ }
+ store.Read([]uint32{msg.Uid}, newReadState, func(
msg types.WorkerMessage) {
switch msg := msg.(type) {
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 050396f..750d2da 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -99,8 +99,12 @@ message list, the message in the message viewer, etc).
*read*
Marks the selected message as read.
+ *-t*: Toggle the selected message between read and unread.
+
*unread*
Marks the selected message as unread.
+
+ *-t*: Toggle the selected message between read and unread.
*unsubscribe*
Attempt to automatically unsubscribe the user from the mailing list through