view: add peek flag and propagate
Add a peek flag -p to the view commands to open the message viewer without setting the "seen" flag. If the flag is set, it would ignore the "auto-mark-read" config. The SetSeen flag will be propagated in case the message viewer moves on to other messages, i.e. with the delete or archive commands. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
e4d418eed1
commit
d3b62dd3b0
6 changed files with 32 additions and 8 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"git.sr.ht/~rjarry/aerc/lib"
|
||||
"git.sr.ht/~rjarry/aerc/widgets"
|
||||
"git.sr.ht/~sircmpwn/getopt"
|
||||
)
|
||||
|
||||
type ViewMessage struct{}
|
||||
|
@ -22,8 +23,20 @@ func (ViewMessage) Complete(aerc *widgets.Aerc, args []string) []string {
|
|||
}
|
||||
|
||||
func (ViewMessage) Execute(aerc *widgets.Aerc, args []string) error {
|
||||
if len(args) != 1 {
|
||||
return errors.New("Usage: view-message")
|
||||
peek := false
|
||||
opts, optind, err := getopt.Getopts(args, "p")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
if opt.Option == 'p' {
|
||||
peek = true
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) != optind {
|
||||
return errors.New("Usage: view-message [-p]")
|
||||
}
|
||||
acct := aerc.SelectedAccount()
|
||||
if acct == nil {
|
||||
|
@ -45,7 +58,7 @@ func (ViewMessage) Execute(aerc *widgets.Aerc, args []string) error {
|
|||
aerc.PushError(msg.Error.Error())
|
||||
return nil
|
||||
}
|
||||
lib.NewMessageStoreView(msg, acct.UiConfig().AutoMarkRead,
|
||||
lib.NewMessageStoreView(msg, !peek && acct.UiConfig().AutoMarkRead,
|
||||
store, aerc.Crypto, aerc.DecryptKeys,
|
||||
func(view lib.MessageView, err error) {
|
||||
if err != nil {
|
||||
|
|
|
@ -120,7 +120,7 @@ func (Archive) Execute(aerc *widgets.Aerc, args []string) error {
|
|||
acct.Messages().Invalidate()
|
||||
return
|
||||
}
|
||||
lib.NewMessageStoreView(next, acct.UiConfig().AutoMarkRead,
|
||||
lib.NewMessageStoreView(next, mv.MessageView().SeenFlagSet(),
|
||||
store, aerc.Crypto, aerc.DecryptKeys,
|
||||
func(view lib.MessageView, err error) {
|
||||
if err != nil {
|
||||
|
|
|
@ -63,7 +63,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
|
|||
acct.Messages().Invalidate()
|
||||
return
|
||||
}
|
||||
lib.NewMessageStoreView(next, acct.UiConfig().AutoMarkRead,
|
||||
lib.NewMessageStoreView(next, mv.MessageView().SeenFlagSet(),
|
||||
store, aerc.Crypto, aerc.DecryptKeys,
|
||||
func(view lib.MessageView, err error) {
|
||||
if err != nil {
|
||||
|
|
|
@ -42,7 +42,7 @@ func (NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error {
|
|||
aerc.RemoveTab(mv)
|
||||
return nil
|
||||
}
|
||||
lib.NewMessageStoreView(nextMsg, acct.UiConfig().AutoMarkRead,
|
||||
lib.NewMessageStoreView(nextMsg, mv.MessageView().SeenFlagSet(),
|
||||
store, aerc.Crypto, aerc.DecryptKeys,
|
||||
func(view lib.MessageView, err error) {
|
||||
if err != nil {
|
||||
|
|
|
@ -374,8 +374,10 @@ message list, the message in the message viewer, etc).
|
|||
*toggle-threads*
|
||||
Toggles between message threading and the normal message list.
|
||||
|
||||
*view*
|
||||
Opens the message viewer to display the selected message.
|
||||
*view* [-p]
|
||||
Opens the message viewer to display the selected message. If the peek
|
||||
flag -p is set, the message will not be marked as "seen" and ignores the
|
||||
"auto-mark-read" config.
|
||||
|
||||
## MESSAGE VIEW COMMANDS
|
||||
|
||||
|
|
|
@ -29,6 +29,9 @@ type MessageView interface {
|
|||
FetchBodyPart(part []int, cb func(io.Reader))
|
||||
|
||||
MessageDetails() *models.MessageDetails
|
||||
|
||||
// SeenFlagSet returns true if the "seen" flag has been set
|
||||
SeenFlagSet() bool
|
||||
}
|
||||
|
||||
func usePGP(info *models.BodyStructure) bool {
|
||||
|
@ -56,6 +59,7 @@ type MessageStoreView struct {
|
|||
message []byte
|
||||
details *models.MessageDetails
|
||||
bodyStructure *models.BodyStructure
|
||||
setSeen bool
|
||||
}
|
||||
|
||||
func NewMessageStoreView(messageInfo *models.MessageInfo, setSeen bool,
|
||||
|
@ -65,6 +69,7 @@ func NewMessageStoreView(messageInfo *models.MessageInfo, setSeen bool,
|
|||
msv := &MessageStoreView{
|
||||
messageInfo, store,
|
||||
nil, nil, messageInfo.BodyStructure,
|
||||
setSeen,
|
||||
}
|
||||
|
||||
if usePGP(messageInfo.BodyStructure) {
|
||||
|
@ -102,6 +107,10 @@ func NewMessageStoreView(messageInfo *models.MessageInfo, setSeen bool,
|
|||
}
|
||||
}
|
||||
|
||||
func (msv *MessageStoreView) SeenFlagSet() bool {
|
||||
return msv.setSeen
|
||||
}
|
||||
|
||||
func (msv *MessageStoreView) MessageInfo() *models.MessageInfo {
|
||||
return msv.messageInfo
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue