mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 18:17:03 +00:00
Implement recent mailboxes feature
This commit is contained in:
@@ -28,7 +28,22 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="navbar" class="collapse navbar-collapse">
|
<div id="navbar" class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li id="nav-mail"><a href="/" accesskey="1">Mail</a></li>
|
{{with .ctx.Session.Values.recentMailboxes}}
|
||||||
|
<li id="nav-mail" class="dropdown">
|
||||||
|
<a class="dropdown-toggle"
|
||||||
|
href="#"
|
||||||
|
accesskey="1"
|
||||||
|
data-toggle="dropdown"
|
||||||
|
role="button"
|
||||||
|
aria-haspopup="true"
|
||||||
|
aria-expanded="false">Recent Mailboxes <span class="caret"></span></a>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
{{range .}}
|
||||||
|
<li><a href="{{reverse "MailboxIndex"}}?name={{.}}">{{.}}</a></li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
<li id="nav-status"><a href="/status" accesskey="2">Status</a></li>
|
<li id="nav-status"><a href="/status" accesskey="2">Status</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<form class="navbar-form navbar-right" action="{{reverse "MailboxIndex"}}" method="GET">
|
<form class="navbar-form navbar-right" action="{{reverse "MailboxIndex"}}" method="GET">
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *Context) (err e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remember this mailbox was visited
|
||||||
|
RememberMailbox(ctx, name)
|
||||||
|
|
||||||
return RenderTemplate("mailbox/index.html", w, map[string]interface{}{
|
return RenderTemplate("mailbox/index.html", w, map[string]interface{}{
|
||||||
"ctx": ctx,
|
"ctx": ctx,
|
||||||
"name": name,
|
"name": name,
|
||||||
|
|||||||
31
web/recent.go
Normal file
31
web/recent.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
const (
|
||||||
|
// maximum mailboxes to remember
|
||||||
|
maxRemembered = 8
|
||||||
|
// session value key; referenced in templates, do not change
|
||||||
|
mailboxKey = "recentMailboxes"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RememberMailbox manages the list of recently accessed mailboxes stored in the session
|
||||||
|
func RememberMailbox(ctx *Context, mailbox string) {
|
||||||
|
recent := RecentMailboxes(ctx)
|
||||||
|
newRecent := make([]string, 1, maxRemembered)
|
||||||
|
newRecent[0] = mailbox
|
||||||
|
|
||||||
|
for _, recBox := range recent {
|
||||||
|
// Insert until newRecent is full, but don't repeat the new mailbox
|
||||||
|
if len(newRecent) < maxRemembered && mailbox != recBox {
|
||||||
|
newRecent = append(newRecent, recBox)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Session.Values[mailboxKey] = newRecent
|
||||||
|
}
|
||||||
|
|
||||||
|
// RecentMailboxes returns a slice of the most recently accessed mailboxes
|
||||||
|
func RecentMailboxes(ctx *Context) []string {
|
||||||
|
val := ctx.Session.Values[mailboxKey]
|
||||||
|
recent, _ := val.([]string)
|
||||||
|
return recent
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user