about summary refs log tree commit diff stats
path: root/commands
diff options
context:
space:
mode:
authorKevin Kuehler <keur@ocf.berkeley.edu>2019-06-01 22:15:04 -0700
committerDrew DeVault <sir@cmpwn.com>2019-06-02 10:16:29 -0400
commit753adb90692e4821f8caea1d5d86cd69e312efa7 (patch)
tree79f7563e0ef68264b12244160b3274b678875624 /commands
parent2be985fecb0d76e8fa7cdc46c8de92b6caab9552 (diff)
downloadaerc-753adb90692e4821f8caea1d5d86cd69e312efa7.tar.gz
widget: Add ProvidesMessage interface
Consists of 3 functions
* Store: Access to MessageStore type
* SelectedAccount: Access to Account widget that the target widget
belongs to
* SelectedMessage: Current message (selected in msglist or the one we
are viewing)

Signed-off-by: Kevin Kuehler <keur@ocf.berkeley.edu>
Diffstat (limited to 'commands')
-rw-r--r--commands/account/view.go2
-rw-r--r--commands/msg/copy.go (renamed from commands/account/copy.go)9
-rw-r--r--commands/msg/delete.go (renamed from commands/account/delete.go)14
-rw-r--r--commands/msg/move.go (renamed from commands/account/move.go)13
-rw-r--r--commands/msg/msg.go16
-rw-r--r--commands/msg/reply.go (renamed from commands/account/reply.go)12
6 files changed, 49 insertions, 17 deletions
diff --git a/commands/account/view.go b/commands/account/view.go
index 40abec3..f7f3ec6 100644
--- a/commands/account/view.go
+++ b/commands/account/view.go
@@ -24,7 +24,7 @@ func ViewMessage(aerc *widgets.Aerc, args []string) error {
 	if msg == nil {
 		return nil
 	}
-	viewer := widgets.NewMessageViewer(aerc.Config(), store, msg)
+	viewer := widgets.NewMessageViewer(acct, aerc.Config(), store, msg)
 	aerc.NewTab(viewer, msg.Envelope.Subject)
 	return nil
 }
diff --git a/commands/account/copy.go b/commands/msg/copy.go
index da26fec..57c93a3 100644
--- a/commands/account/copy.go
+++ b/commands/msg/copy.go
@@ -1,4 +1,4 @@
-package account
+package msg
 
 import (
 	"errors"
@@ -19,12 +19,13 @@ func Copy(aerc *widgets.Aerc, args []string) error {
 	if len(args) != 2 {
 		return errors.New("Usage: mv <folder>")
 	}
-	acct := aerc.SelectedAccount()
+	widget := aerc.SelectedTab().(widgets.ProvidesMessage)
+	acct := widget.SelectedAccount()
 	if acct == nil {
 		return errors.New("No account selected")
 	}
-	msg := acct.Messages().Selected()
-	store := acct.Messages().Store()
+	msg := widget.SelectedMessage()
+	store := widget.Store()
 	store.Copy([]uint32{msg.Uid}, args[1], func(msg types.WorkerMessage) {
 		switch msg := msg.(type) {
 		case *types.Done:
diff --git a/commands/account/delete.go b/commands/msg/delete.go
index 65d6eb9..082dbe3 100644
--- a/commands/account/delete.go
+++ b/commands/msg/delete.go
@@ -1,4 +1,4 @@
-package account
+package msg
 
 import (
 	"errors"
@@ -19,12 +19,18 @@ func DeleteMessage(aerc *widgets.Aerc, args []string) error {
 	if len(args) != 1 {
 		return errors.New("Usage: :delete")
 	}
-	acct := aerc.SelectedAccount()
+
+	widget := aerc.SelectedTab().(widgets.ProvidesMessage)
+	acct := widget.SelectedAccount()
 	if acct == nil {
 		return errors.New("No account selected")
 	}
-	store := acct.Messages().Store()
-	msg := acct.Messages().Selected()
+	store := widget.Store()
+	msg := widget.SelectedMessage()
+	_, isMsgView := widget.(*widgets.MessageViewer)
+	if isMsgView {
+		aerc.RemoveTab(widget)
+	}
 	acct.Messages().Next()
 	store.Delete([]uint32{msg.Uid}, func(msg types.WorkerMessage) {
 		switch msg := msg.(type) {
diff --git a/commands/account/move.go b/commands/msg/move.go
index d58a279..1224efa 100644
--- a/commands/account/move.go
+++ b/commands/msg/move.go
@@ -1,4 +1,4 @@
-package account
+package msg
 
 import (
 	"errors"
@@ -19,12 +19,17 @@ func Move(aerc *widgets.Aerc, args []string) error {
 	if len(args) != 2 {
 		return errors.New("Usage: mv <folder>")
 	}
-	acct := aerc.SelectedAccount()
+	widget := aerc.SelectedTab().(widgets.ProvidesMessage)
+	acct := widget.SelectedAccount()
 	if acct == nil {
 		return errors.New("No account selected")
 	}
-	msg := acct.Messages().Selected()
-	store := acct.Messages().Store()
+	msg := widget.SelectedMessage()
+	store := widget.Store()
+	_, isMsgView := widget.(*widgets.MessageViewer)
+	if isMsgView {
+		aerc.RemoveTab(widget)
+	}
 	acct.Messages().Next()
 	store.Move([]uint32{msg.Uid}, args[1], func(msg types.WorkerMessage) {
 		switch msg := msg.(type) {
diff --git a/commands/msg/msg.go b/commands/msg/msg.go
new file mode 100644
index 0000000..73755aa
--- /dev/null
+++ b/commands/msg/msg.go
@@ -0,0 +1,16 @@
+package msg
+
+import (
+	"git.sr.ht/~sircmpwn/aerc/commands"
+)
+
+var (
+	MessageCommands *commands.Commands
+)
+
+func register(name string, cmd commands.AercCommand) {
+	if MessageCommands == nil {
+		MessageCommands = commands.NewCommands()
+	}
+	MessageCommands.Register(name, cmd)
+}
diff --git a/commands/account/reply.go b/commands/msg/reply.go
index ecc6239..e09a118 100644
--- a/commands/account/reply.go
+++ b/commands/msg/reply.go
@@ -1,4 +1,4 @@
-package account
+package msg
 
 import (
 	"bufio"
@@ -63,11 +63,15 @@ func Reply(aerc *widgets.Aerc, args []string) error {
 		}
 	}
 
-	acct := aerc.SelectedAccount()
+	widget := aerc.SelectedTab().(widgets.ProvidesMessage)
+	acct := widget.SelectedAccount()
+	if acct == nil {
+		return errors.New("No account selected")
+	}
 	conf := acct.AccountConfig()
 	us, _ := gomail.ParseAddress(conf.From)
-	store := acct.Messages().Store()
-	msg := acct.Messages().Selected()
+	store := widget.Store()
+	msg := widget.SelectedMessage()
 	acct.Logger().Println("Replying to email " + msg.Envelope.MessageId)
 
 	var (