diff options
-rw-r--r-- | commands/msg/archive.go | 35 | ||||
-rw-r--r-- | commands/msg/move.go | 65 | ||||
-rw-r--r-- | doc/aerc-config.5.scd | 2 |
3 files changed, 58 insertions, 44 deletions
diff --git a/commands/msg/archive.go b/commands/msg/archive.go index beba3a63..b0c7b038 100644 --- a/commands/msg/archive.go +++ b/commands/msg/archive.go @@ -5,11 +5,8 @@ import ( "fmt" "path" "sync" - "time" "git.sr.ht/~rjarry/aerc/commands" - "git.sr.ht/~rjarry/aerc/lib" - "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -108,37 +105,7 @@ func (Archive) Execute(aerc *widgets.Aerc, args []string) error { wg.Wait() if success { - aerc.PushStatus("Messages archived.", 10*time.Second) - mv, isMsgView := h.msgProvider.(*widgets.MessageViewer) - if isMsgView { - if !aerc.Config().Ui.NextMessageOnDelete { - aerc.RemoveTab(h.msgProvider) - } else { - // no more messages in the list - if next == nil { - aerc.RemoveTab(h.msgProvider) - acct.Messages().Select(-1) - ui.Invalidate() - return - } - lib.NewMessageStoreView(next, mv.MessageView().SeenFlagSet(), - store, aerc.Crypto, aerc.DecryptKeys, - func(view lib.MessageView, err error) { - if err != nil { - aerc.PushError(err.Error()) - return - } - nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view) - aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject) - }) - } - } else { - if next == nil { - // We archived the last message, select the new last message - // instead of the first message - acct.Messages().Select(-1) - } - } + handleDone(aerc, acct, next, "Messages archived.", store) } }() return nil diff --git a/commands/msg/move.go b/commands/msg/move.go index 13b1fb7b..15494364 100644 --- a/commands/msg/move.go +++ b/commands/msg/move.go @@ -5,11 +5,13 @@ import ( "strings" "time" - "git.sr.ht/~sircmpwn/getopt" - "git.sr.ht/~rjarry/aerc/commands" + "git.sr.ht/~rjarry/aerc/lib" + "git.sr.ht/~rjarry/aerc/lib/ui" + "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" "git.sr.ht/~rjarry/aerc/worker/types" + "git.sr.ht/~sircmpwn/getopt" ) type Move struct{} @@ -42,32 +44,77 @@ func (Move) Execute(aerc *widgets.Aerc, args []string) error { } h := newHelper(aerc) + acct, err := h.account() + if err != nil { + return err + } store, err := h.store() if err != nil { return err } - uids, err := h.markedOrSelectedUids() + msgs, err := h.messages() if err != nil { return err } - _, isMsgView := h.msgProvider.(*widgets.MessageViewer) - if isMsgView { - aerc.RemoveTab(h.msgProvider) + var uids []uint32 + for _, msg := range msgs { + uids = append(uids, msg.Uid) } marker := store.Marker() marker.ClearVisualMark() - findNextNonDeleted(uids, store) + next := findNextNonDeleted(uids, store) joinedArgs := strings.Join(args[optind:], " ") + store.Move(uids, joinedArgs, createParents, func( msg types.WorkerMessage, ) { switch msg := msg.(type) { case *types.Done: - aerc.PushStatus("Message moved to "+joinedArgs, 10*time.Second) + handleDone(aerc, acct, next, "Messages moved to "+joinedArgs, store) case *types.Error: - marker.Remark() aerc.PushError(msg.Error.Error()) + marker.Remark() } }) + return nil } + +func handleDone( + aerc *widgets.Aerc, + acct *widgets.AccountView, + next *models.MessageInfo, + message string, + store *lib.MessageStore, +) { + h := newHelper(aerc) + aerc.PushStatus(message, 10*time.Second) + mv, isMsgView := h.msgProvider.(*widgets.MessageViewer) + switch { + case isMsgView && !aerc.Config().Ui.NextMessageOnDelete: + aerc.RemoveTab(h.msgProvider) + case isMsgView: + if next == nil { + aerc.RemoveTab(h.msgProvider) + acct.Messages().Select(-1) + ui.Invalidate() + return + } + lib.NewMessageStoreView(next, mv.MessageView().SeenFlagSet(), + store, aerc.Crypto, aerc.DecryptKeys, + func(view lib.MessageView, err error) { + if err != nil { + aerc.PushError(err.Error()) + return + } + nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view) + aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject) + }) + default: + if next == nil { + // We moved the last message, select the new last message + // instead of the first message + acct.Messages().Select(-1) + } + } +} diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd index d943c18e..e40630bc 100644 --- a/doc/aerc-config.5.scd +++ b/doc/aerc-config.5.scd @@ -237,7 +237,7 @@ These options are configured in the *[ui]* section of aerc.conf. Default: 0 *next-message-on-delete* - Moves to next message when the current message is deleted + Moves to next message when the current message is deleted, archived, or moved. Default: true |