From ae675b491d2b55a06588e8ab4ce8205aaae796c8 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 20 Dec 2022 17:05:43 +0100 Subject: templates: change fields as lazy functions No need to pre-render fields that are not necessarily accessed in templates. Change fields to functions that are evaluated only when required. Signed-off-by: Robin Jarry Acked-by: Tim Culverhouse --- commands/account/compose.go | 3 +-- commands/account/recover.go | 3 +-- commands/msg/forward.go | 2 +- commands/msg/invite.go | 2 +- commands/msg/recall.go | 2 +- commands/msg/reply.go | 3 ++- commands/msg/unsubscribe.go | 3 +-- 7 files changed, 8 insertions(+), 10 deletions(-) (limited to 'commands') diff --git a/commands/account/compose.go b/commands/account/compose.go index fb37b231..5695bb7d 100644 --- a/commands/account/compose.go +++ b/commands/account/compose.go @@ -13,7 +13,6 @@ import ( "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/log" - "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" "git.sr.ht/~sircmpwn/getopt" ) @@ -55,7 +54,7 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error { composer, err := widgets.NewComposer(aerc, acct, acct.AccountConfig(), acct.Worker(), - template, &headers, models.OriginalMail{}) + template, &headers, nil) if err != nil { return err } diff --git a/commands/account/recover.go b/commands/account/recover.go index 8ce878ee..cef0720f 100644 --- a/commands/account/recover.go +++ b/commands/account/recover.go @@ -10,7 +10,6 @@ import ( "git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/log" - "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" "git.sr.ht/~sircmpwn/getopt" ) @@ -103,7 +102,7 @@ func (Recover) Execute(aerc *widgets.Aerc, args []string) error { composer, err := widgets.NewComposer(aerc, acct, acct.AccountConfig(), acct.Worker(), - "", nil, models.OriginalMail{}) + "", nil, nil) if err != nil { return err } diff --git a/commands/msg/forward.go b/commands/msg/forward.go index 9a4f3d41..90c32ec2 100644 --- a/commands/msg/forward.go +++ b/commands/msg/forward.go @@ -101,7 +101,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error { addTab := func() (*widgets.Composer, error) { composer, err := widgets.NewComposer(aerc, acct, - acct.AccountConfig(), acct.Worker(), template, h, original) + acct.AccountConfig(), acct.Worker(), template, h, &original) if err != nil { aerc.PushError("Error: " + err.Error()) return nil, err diff --git a/commands/msg/invite.go b/commands/msg/invite.go index ef28b91c..1528abea 100644 --- a/commands/msg/invite.go +++ b/commands/msg/invite.go @@ -139,7 +139,7 @@ func (invite) Execute(aerc *widgets.Aerc, args []string) error { addTab := func(cr *calendar.Reply) error { composer, err := widgets.NewComposer(aerc, acct, - acct.AccountConfig(), acct.Worker(), "", h, original) + acct.AccountConfig(), acct.Worker(), "", h, &original) if err != nil { aerc.PushError("Error: " + err.Error()) return err diff --git a/commands/msg/recall.go b/commands/msg/recall.go index f106e8bd..2ef468e0 100644 --- a/commands/msg/recall.go +++ b/commands/msg/recall.go @@ -74,7 +74,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error { composer, err := widgets.NewComposer(aerc, acct, acct.AccountConfig(), acct.Worker(), "", msgInfo.RFC822Headers, - models.OriginalMail{}) + nil) if err != nil { return errors.Wrap(err, "Cannot open a new composer") } diff --git a/commands/msg/reply.go b/commands/msg/reply.go index 795158ca..f8cde644 100644 --- a/commands/msg/reply.go +++ b/commands/msg/reply.go @@ -175,7 +175,8 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { mv, _ := aerc.SelectedTabContent().(*widgets.MessageViewer) addTab := func() error { composer, err := widgets.NewComposer(aerc, acct, - acct.AccountConfig(), acct.Worker(), template, h, original) + acct.AccountConfig(), acct.Worker(), template, h, + &original) if err != nil { aerc.PushError("Error: " + err.Error()) return err diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go index a334e827..66797660 100644 --- a/commands/msg/unsubscribe.go +++ b/commands/msg/unsubscribe.go @@ -11,7 +11,6 @@ import ( "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/log" - "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" "github.com/emersion/go-message/mail" ) @@ -155,7 +154,7 @@ func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error { acct.Worker(), "", h, - models.OriginalMail{}, + nil, ) if err != nil { return err -- cgit