Add INBOX unread count on mailbox/message pages
This commit is contained in:
parent
0a9c246794
commit
9a7acd2791
3 changed files with 40 additions and 13 deletions
|
@ -66,6 +66,7 @@ func registerRoutes(p *alps.GoPlugin) {
|
||||||
type MailboxRenderData struct {
|
type MailboxRenderData struct {
|
||||||
alps.BaseRenderData
|
alps.BaseRenderData
|
||||||
Mailbox *MailboxStatus
|
Mailbox *MailboxStatus
|
||||||
|
Inbox *MailboxStatus
|
||||||
Mailboxes []MailboxInfo
|
Mailboxes []MailboxInfo
|
||||||
Messages []IMAPMessage
|
Messages []IMAPMessage
|
||||||
PrevPage, NextPage int
|
PrevPage, NextPage int
|
||||||
|
@ -96,7 +97,7 @@ func handleGetMailbox(ctx *alps.Context) error {
|
||||||
|
|
||||||
var mailboxes []MailboxInfo
|
var mailboxes []MailboxInfo
|
||||||
var msgs []IMAPMessage
|
var msgs []IMAPMessage
|
||||||
var mbox *MailboxStatus
|
var mbox, inbox *MailboxStatus
|
||||||
var total int
|
var total int
|
||||||
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
|
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
|
||||||
var err error
|
var err error
|
||||||
|
@ -114,6 +115,13 @@ func handleGetMailbox(ctx *alps.Context) error {
|
||||||
if mbox, err = getMailboxStatus(c, mboxName); err != nil {
|
if mbox, err = getMailboxStatus(c, mboxName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if mboxName == "INBOX" {
|
||||||
|
inbox = mbox
|
||||||
|
} else {
|
||||||
|
if inbox, err = getMailboxStatus(c, "INBOX"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -149,6 +157,7 @@ func handleGetMailbox(ctx *alps.Context) error {
|
||||||
return ctx.Render(http.StatusOK, "mailbox.html", &MailboxRenderData{
|
return ctx.Render(http.StatusOK, "mailbox.html", &MailboxRenderData{
|
||||||
BaseRenderData: *alps.NewBaseRenderData(ctx).WithTitle(title),
|
BaseRenderData: *alps.NewBaseRenderData(ctx).WithTitle(title),
|
||||||
Mailbox: mbox,
|
Mailbox: mbox,
|
||||||
|
Inbox: inbox,
|
||||||
Mailboxes: mailboxes,
|
Mailboxes: mailboxes,
|
||||||
Messages: msgs,
|
Messages: msgs,
|
||||||
PrevPage: prevPage,
|
PrevPage: prevPage,
|
||||||
|
@ -207,6 +216,7 @@ type MessageRenderData struct {
|
||||||
alps.BaseRenderData
|
alps.BaseRenderData
|
||||||
Mailboxes []MailboxInfo
|
Mailboxes []MailboxInfo
|
||||||
Mailbox *MailboxStatus
|
Mailbox *MailboxStatus
|
||||||
|
Inbox *MailboxStatus
|
||||||
Message *IMAPMessage
|
Message *IMAPMessage
|
||||||
Part *IMAPPartNode
|
Part *IMAPPartNode
|
||||||
View interface{}
|
View interface{}
|
||||||
|
@ -233,7 +243,7 @@ func handleGetPart(ctx *alps.Context, raw bool) error {
|
||||||
var mailboxes []MailboxInfo
|
var mailboxes []MailboxInfo
|
||||||
var msg *IMAPMessage
|
var msg *IMAPMessage
|
||||||
var part *message.Entity
|
var part *message.Entity
|
||||||
var mbox *MailboxStatus
|
var mbox, inbox *MailboxStatus
|
||||||
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
|
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
|
||||||
var err error
|
var err error
|
||||||
if mailboxes, err = listMailboxes(c); err != nil {
|
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 {
|
if mbox, err = getMailboxStatus(c, mboxName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if mboxName == "INBOX" {
|
||||||
|
inbox = mbox
|
||||||
|
} else {
|
||||||
|
if inbox, err = getMailboxStatus(c, "INBOX"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -306,6 +323,7 @@ func handleGetPart(ctx *alps.Context, raw bool) error {
|
||||||
WithTitle(msg.Envelope.Subject),
|
WithTitle(msg.Envelope.Subject),
|
||||||
Mailboxes: mailboxes,
|
Mailboxes: mailboxes,
|
||||||
Mailbox: mbox,
|
Mailbox: mbox,
|
||||||
|
Inbox: inbox,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
Part: msg.PartByPath(partPath),
|
Part: msg.PartByPath(partPath),
|
||||||
View: view,
|
View: view,
|
||||||
|
|
|
@ -5,18 +5,22 @@
|
||||||
<aside>
|
<aside>
|
||||||
<!-- the logo image, dimensions 200x32 may be present or not -->
|
<!-- the logo image, dimensions 200x32 may be present or not -->
|
||||||
<a href="/compose" class="new">Compose Mail</a>
|
<a href="/compose" class="new">Compose Mail</a>
|
||||||
{{$current := .Mailbox}}
|
|
||||||
{{range .Mailboxes}}
|
{{range .Mailboxes}}
|
||||||
<a href="{{.URL}}"
|
<a href="{{.URL}}" {{ if eq $.Mailbox.Name .Name }}class="active"{{ end }}>
|
||||||
{{ if eq $current.Name .Name }}class="active"{{ end }}>
|
|
||||||
{{ if eq .Name "INBOX" }}
|
{{ if eq .Name "INBOX" }}
|
||||||
Inbox
|
Inbox
|
||||||
{{else}}
|
{{ else }}
|
||||||
{{.Name}}
|
{{ .Name }}
|
||||||
{{end}}
|
|
||||||
{{ if eq $current.Name .Name }}
|
|
||||||
{{ if $current.Unseen }}({{ $current.Unseen }}){{ end }}
|
|
||||||
{{ end }}
|
{{ 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>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</aside>
|
</aside>
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
<aside>
|
<aside>
|
||||||
<!-- the logo image, dimensions 200x32 may be present or not -->
|
<!-- the logo image, dimensions 200x32 may be present or not -->
|
||||||
<a href="/compose" class="new">Compose Mail</a>
|
<a href="/compose" class="new">Compose Mail</a>
|
||||||
{{$current := .Mailbox}}
|
|
||||||
{{range .Mailboxes}}
|
{{range .Mailboxes}}
|
||||||
<a href="{{.URL}}"
|
<a href="{{.URL}}"
|
||||||
{{ if eq $current.Name .Name }}class="active"{{ end }}>
|
{{ if eq $current.Name .Name }}class="active"{{ end }}>
|
||||||
|
@ -41,9 +40,15 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
{{.Name}}
|
{{.Name}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{ if eq $current.Name .Name }}
|
|
||||||
{{ if $current.Unseen }}({{ $current.Unseen }}){{ end }}
|
{{ $unseen := 0 }}
|
||||||
|
{{ if eq .Name "INBOX" }}
|
||||||
|
{{ $unseen = $.Inbox.Unseen }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ if eq .Name $.Mailbox.Name }}
|
||||||
|
{{ $unseen = $.Mailbox.Unseen }}
|
||||||
|
{{ end }}
|
||||||
|
{{ if $unseen }}({{ $unseen }}){{ end }}
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</aside>
|
</aside>
|
||||||
|
|
Loading…
Add table
Reference in a new issue