Add an option to toggle between read and unread

This commit is contained in:
Nicolai Dagestad 2019-07-15 19:51:07 +02:00 committed by Drew DeVault
parent dbd583c969
commit a1763bf207
2 changed files with 33 additions and 3 deletions

View File

@ -4,8 +4,11 @@ import (
"errors" "errors"
"time" "time"
"git.sr.ht/~sircmpwn/getopt"
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets" "git.sr.ht/~sircmpwn/aerc/widgets"
"git.sr.ht/~sircmpwn/aerc/worker/types" "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 { func (_ Read) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) != 1 { opts, optind, err := getopt.Getopts(args, "t")
return errors.New("Usage: " + args[0]) 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) widget := aerc.SelectedTab().(widgets.ProvidesMessage)
@ -38,7 +53,18 @@ func (_ Read) Execute(aerc *widgets.Aerc, args []string) error {
if err != nil { if err != nil {
return err 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) { msg types.WorkerMessage) {
switch msg := msg.(type) { switch msg := msg.(type) {

View File

@ -99,8 +99,12 @@ message list, the message in the message viewer, etc).
*read* *read*
Marks the selected message as read. Marks the selected message as read.
*-t*: Toggle the selected message between read and unread.
*unread* *unread*
Marks the selected message as unread. Marks the selected message as unread.
*-t*: Toggle the selected message between read and unread.
*unsubscribe* *unsubscribe*
Attempt to automatically unsubscribe the user from the mailing list through Attempt to automatically unsubscribe the user from the mailing list through