From d8c2d63ee9b37e78d0e06ec71b2227b83ee52aa5 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Sun, 16 Apr 2023 09:53:46 -0500 Subject: directory: add role to template fields Add .Role as a template field for use in distinguishing between mailboxes with a given IANA role, or custom role defined by aerc ("query" for notmuch queries, for example). Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- lib/state/templates.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'lib/state') diff --git a/lib/state/templates.go b/lib/state/templates.go index f971b62c..e93d0bb0 100644 --- a/lib/state/templates.go +++ b/lib/state/templates.go @@ -29,7 +29,7 @@ type TemplateData struct { // selected account account *config.AccountConfig myAddresses map[string]bool - folder string // selected folder name + folder *models.Directory // selected folder folders []string getRUEcount func(string) (int, int, int) @@ -66,7 +66,7 @@ func (d *TemplateData) SetAccount(acct *config.AccountConfig) { } } -func (d *TemplateData) SetFolder(folder string) { +func (d *TemplateData) SetFolder(folder *models.Directory) { d.folder = folder } @@ -91,11 +91,21 @@ func (d *TemplateData) Account() string { } func (d *TemplateData) Folder() string { - return d.folder + if d.folder != nil { + return d.folder.Name + } + return "" +} + +func (d *TemplateData) Role() string { + if d.folder != nil { + return string(d.folder.Role) + } + return "" } func (d *TemplateData) ui() *config.UIConfig { - return config.Ui.ForAccount(d.Account()).ForFolder(d.folder) + return config.Ui.ForAccount(d.Account()).ForFolder(d.Folder()) } func (d *TemplateData) To() []*mail.Address { @@ -425,7 +435,7 @@ func (d *TemplateData) ContentInfo() string { return "" } var content []string - fldr := d.state.folderState(d.folder) + fldr := d.state.folderState(d.Folder()) if fldr.FilterActivity != "" { content = append(content, fldr.FilterActivity) } else if fldr.Filter != "" { @@ -450,7 +460,7 @@ func (d *TemplateData) TrayInfo() string { return "" } var tray []string - fldr := d.state.folderState(d.folder) + fldr := d.state.folderState(d.Folder()) if fldr.Sorting { tray = append(tray, texter().Sorting()) } -- cgit