Add modify-labels command
This adds the event type as well as the command implementation, but no backend supports it yet.
This commit is contained in:
parent
618a500341
commit
a93b4de6f3
5 changed files with 96 additions and 3 deletions
69
commands/msg/modify-labels.go
Normal file
69
commands/msg/modify-labels.go
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
package msg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.sr.ht/~sircmpwn/aerc/widgets"
|
||||||
|
"git.sr.ht/~sircmpwn/aerc/worker/types"
|
||||||
|
"github.com/gdamore/tcell"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ModifyLabels struct{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
register(ModifyLabels{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ModifyLabels) Aliases() []string {
|
||||||
|
return []string{"modify-labels"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ModifyLabels) Complete(aerc *widgets.Aerc, args []string) []string {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ModifyLabels) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
|
changes := args[1:]
|
||||||
|
if len(changes) == 0 {
|
||||||
|
return errors.New("Usage: modify-labels <[+-]label> ...")
|
||||||
|
}
|
||||||
|
|
||||||
|
widget := aerc.SelectedTab().(widgets.ProvidesMessage)
|
||||||
|
acct := widget.SelectedAccount()
|
||||||
|
if acct == nil {
|
||||||
|
return errors.New("No account selected")
|
||||||
|
}
|
||||||
|
store := widget.Store()
|
||||||
|
if store == nil {
|
||||||
|
return errors.New("Cannot perform action. Messages still loading")
|
||||||
|
}
|
||||||
|
msg, err := widget.SelectedMessage()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var add, remove []string
|
||||||
|
for _, l := range changes {
|
||||||
|
switch l[0] {
|
||||||
|
case '+':
|
||||||
|
add = append(add, l[1:])
|
||||||
|
case '-':
|
||||||
|
remove = append(remove, l[1:])
|
||||||
|
default:
|
||||||
|
// if no operand is given assume add
|
||||||
|
add = append(add, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
store.ModifyLabels([]uint32{msg.Uid}, add, remove, func(
|
||||||
|
msg types.WorkerMessage) {
|
||||||
|
|
||||||
|
switch msg := msg.(type) {
|
||||||
|
case *types.Done:
|
||||||
|
aerc.PushStatus("labels updated", 10*time.Second)
|
||||||
|
case *types.Error:
|
||||||
|
aerc.PushStatus(" "+msg.Error.Error(), 10*time.Second).
|
||||||
|
Color(tcell.ColorDefault, tcell.ColorRed)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -133,6 +133,14 @@ message list, the message in the message viewer, etc).
|
||||||
|
|
||||||
*-t*: Toggle the selected message between read and unread.
|
*-t*: Toggle the selected message between read and unread.
|
||||||
|
|
||||||
|
*modify-labels* <[+-]label>...
|
||||||
|
Modify message labels (e.g. notmuch tags). Labels prefixed with a '+' are
|
||||||
|
added, those prefixed with a '-' removed. As a convenience, labels without
|
||||||
|
either operand add the specified label.
|
||||||
|
|
||||||
|
Example: `modify-labels +inbox -spam unread` adds the labels inbox and unread
|
||||||
|
and removes spam
|
||||||
|
|
||||||
*unsubscribe*
|
*unsubscribe*
|
||||||
Attempt to automatically unsubscribe the user from the mailing list through
|
Attempt to automatically unsubscribe the user from the mailing list through
|
||||||
use of the List-Unsubscribe header. If supported, aerc may open a compose
|
use of the List-Unsubscribe header. If supported, aerc may open a compose
|
||||||
|
|
|
@ -425,3 +425,12 @@ func (store *MessageStore) NextResult() {
|
||||||
func (store *MessageStore) PrevResult() {
|
func (store *MessageStore) PrevResult() {
|
||||||
store.nextPrevResult(-1)
|
store.nextPrevResult(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (store *MessageStore) ModifyLabels(uids []uint32, add, remove []string,
|
||||||
|
cb func(msg types.WorkerMessage)) {
|
||||||
|
store.worker.PostAction(&types.ModifyLabels{
|
||||||
|
Uids: uids,
|
||||||
|
Add: add,
|
||||||
|
Remove: remove,
|
||||||
|
}, cb)
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package widgets
|
package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@ import (
|
||||||
|
|
||||||
type Spinner struct {
|
type Spinner struct {
|
||||||
ui.Invalidatable
|
ui.Invalidatable
|
||||||
frame int64 // access via atomic
|
frame int64 // access via atomic
|
||||||
frames []string
|
frames []string
|
||||||
stop chan struct{}
|
stop chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSpinner(uiConf *config.UIConfig) *Spinner {
|
func NewSpinner(uiConf *config.UIConfig) *Spinner {
|
||||||
|
|
|
@ -175,3 +175,10 @@ type MessagesDeleted struct {
|
||||||
Message
|
Message
|
||||||
Uids []uint32
|
Uids []uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ModifyLabels struct {
|
||||||
|
Message
|
||||||
|
Uids []uint32
|
||||||
|
Add []string
|
||||||
|
Remove []string
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue