aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-07-05 21:42:42 +0200
committerRobin Jarry <robin@jarry.cc>2022-07-10 20:36:24 +0200
commit99b74dbcc98990a3732281f07a2238266f0916dc (patch)
tree31185d7dd26b0e5b75024928cf00b1995acf7b33
parent4821425933ca3c1873f6a7ff8f858ab05f664067 (diff)
downloadaerc-99b74dbcc98990a3732281f07a2238266f0916dc.tar.gz
postpone: avoid calling WriteMessage twice
Postpone will currently call composer.WriteMessage twice: once for counting the bytes and another time for appending the message. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--commands/compose/postpone.go13
1 files changed, 4 insertions, 9 deletions
diff --git a/commands/compose/postpone.go b/commands/compose/postpone.go
index a4ac5c60..f826f681 100644
--- a/commands/compose/postpone.go
+++ b/commands/compose/postpone.go
@@ -1,8 +1,7 @@
package compose
import (
- "io"
- "io/ioutil"
+ "bytes"
"time"
"github.com/miolini/datacounter"
@@ -82,33 +81,29 @@ func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
}
aerc.RemoveTab(composer)
- ctr := datacounter.NewWriterCounter(ioutil.Discard)
+ var buf bytes.Buffer
+ ctr := datacounter.NewWriterCounter(&buf)
err = composer.WriteMessage(header, ctr)
if err != nil {
handleErr(errors.Wrap(err, "WriteMessage"))
return
}
nbytes := int(ctr.Count())
- r, w := io.Pipe()
worker.PostAction(&types.AppendMessage{
Destination: config.Postpone,
Flags: []models.Flag{models.SeenFlag},
Date: time.Now(),
- Reader: r,
+ Reader: &buf,
Length: int(nbytes),
}, func(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
aerc.PushStatus("Message postponed.", 10*time.Second)
- r.Close()
composer.Close()
case *types.Error:
- r.Close()
handleErr(msg.Error)
}
})
- composer.WriteMessage(header, w)
- w.Close()
}()
if !alreadyCreated {