diff options
author | Simon Ser <contact@emersion.fr> | 2020-05-21 19:19:17 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-05-21 19:19:17 +0200 |
commit | 9a7acd27919900edae5a8cdda29e02fd96d2f1ce (patch) | |
tree | 2f74fdf2d219e457c1b89217974f8d3b1432dae7 | |
parent | 0a9c246794b7cec7e5ec510dd8af158e1d88cb82 (diff) | |
download | alps-9a7acd27919900edae5a8cdda29e02fd96d2f1ce.tar.gz alps-9a7acd27919900edae5a8cdda29e02fd96d2f1ce.zip |
Add INBOX unread count on mailbox/message pages
-rw-r--r-- | plugins/base/routes.go | 22 | ||||
-rw-r--r-- | themes/alps/mailbox.html | 20 | ||||
-rw-r--r-- | themes/alps/message.html | 11 |
3 files changed, 40 insertions, 13 deletions
diff --git a/plugins/base/routes.go b/plugins/base/routes.go index d023b4b..9280e1d 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -66,6 +66,7 @@ func registerRoutes(p *alps.GoPlugin) { type MailboxRenderData struct { alps.BaseRenderData Mailbox *MailboxStatus + Inbox *MailboxStatus Mailboxes []MailboxInfo Messages []IMAPMessage PrevPage, NextPage int @@ -96,7 +97,7 @@ func handleGetMailbox(ctx *alps.Context) error { var mailboxes []MailboxInfo var msgs []IMAPMessage - var mbox *MailboxStatus + var mbox, inbox *MailboxStatus var total int err = ctx.Session.DoIMAP(func(c *imapclient.Client) error { var err error @@ -114,6 +115,13 @@ func handleGetMailbox(ctx *alps.Context) error { if mbox, err = getMailboxStatus(c, mboxName); err != nil { return err } + if mboxName == "INBOX" { + inbox = mbox + } else { + if inbox, err = getMailboxStatus(c, "INBOX"); err != nil { + return err + } + } return nil }) if err != nil { @@ -149,6 +157,7 @@ func handleGetMailbox(ctx *alps.Context) error { return ctx.Render(http.StatusOK, "mailbox.html", &MailboxRenderData{ BaseRenderData: *alps.NewBaseRenderData(ctx).WithTitle(title), Mailbox: mbox, + Inbox: inbox, Mailboxes: mailboxes, Messages: msgs, PrevPage: prevPage, @@ -207,6 +216,7 @@ type MessageRenderData struct { alps.BaseRenderData Mailboxes []MailboxInfo Mailbox *MailboxStatus + Inbox *MailboxStatus Message *IMAPMessage Part *IMAPPartNode View interface{} @@ -233,7 +243,7 @@ func handleGetPart(ctx *alps.Context, raw bool) error { var mailboxes []MailboxInfo var msg *IMAPMessage var part *message.Entity - var mbox *MailboxStatus + var mbox, inbox *MailboxStatus err = ctx.Session.DoIMAP(func(c *imapclient.Client) error { var err error if mailboxes, err = listMailboxes(c); err != nil { @@ -245,6 +255,13 @@ func handleGetPart(ctx *alps.Context, raw bool) error { if mbox, err = getMailboxStatus(c, mboxName); err != nil { return err } + if mboxName == "INBOX" { + inbox = mbox + } else { + if inbox, err = getMailboxStatus(c, "INBOX"); err != nil { + return err + } + } return nil }) if err != nil { @@ -306,6 +323,7 @@ func handleGetPart(ctx *alps.Context, raw bool) error { WithTitle(msg.Envelope.Subject), Mailboxes: mailboxes, Mailbox: mbox, + Inbox: inbox, Message: msg, Part: msg.PartByPath(partPath), View: view, diff --git a/themes/alps/mailbox.html b/themes/alps/mailbox.html index 8d9aa54..93a45ce 100644 --- a/themes/alps/mailbox.html +++ b/themes/alps/mailbox.html @@ -5,18 +5,22 @@ <aside> <!-- the logo image, dimensions 200x32 may be present or not --> <a href="/compose" class="new">Compose Mail</a> - {{$current := .Mailbox}} {{range .Mailboxes}} - <a href="{{.URL}}" - {{ if eq $current.Name .Name }}class="active"{{ end }}> + <a href="{{.URL}}" {{ if eq $.Mailbox.Name .Name }}class="active"{{ end }}> {{ if eq .Name "INBOX" }} Inbox - {{else}} - {{.Name}} - {{end}} - {{ if eq $current.Name .Name }} - {{ if $current.Unseen }}({{ $current.Unseen }}){{ end }} + {{ else }} + {{ .Name }} {{ end }} + + {{ $unseen := 0 }} + {{ if eq .Name "INBOX" }} + {{ $unseen = $.Inbox.Unseen }} + {{ end }} + {{ if eq .Name $.Mailbox.Name }} + {{ $unseen = $.Mailbox.Unseen }} + {{ end }} + {{ if $unseen }}({{ $unseen }}){{ end }} </a> {{end}} </aside> diff --git a/themes/alps/message.html b/themes/alps/message.html index 521e835..1d74489 100644 --- a/themes/alps/message.html +++ b/themes/alps/message.html @@ -32,7 +32,6 @@ <aside> <!-- the logo image, dimensions 200x32 may be present or not --> <a href="/compose" class="new">Compose Mail</a> - {{$current := .Mailbox}} {{range .Mailboxes}} <a href="{{.URL}}" {{ if eq $current.Name .Name }}class="active"{{ end }}> @@ -41,9 +40,15 @@ {{else}} {{.Name}} {{end}} - {{ if eq $current.Name .Name }} - {{ if $current.Unseen }}({{ $current.Unseen }}){{ end }} + + {{ $unseen := 0 }} + {{ if eq .Name "INBOX" }} + {{ $unseen = $.Inbox.Unseen }} + {{ end }} + {{ if eq .Name $.Mailbox.Name }} + {{ $unseen = $.Mailbox.Unseen }} {{ end }} + {{ if $unseen }}({{ $unseen }}){{ end }} </a> {{end}} </aside> |