aboutsummaryrefslogtreecommitdiff
path: root/handlers.go
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2019-12-09 16:17:36 +0100
committerSimon Ser <contact@emersion.fr>2019-12-09 16:17:36 +0100
commit9617b412e8f1a2e3c3d112bbf5ece29bc2af37ee (patch)
treecd7c40bffb7c86543ba044eb9ba00dfd1e51db73 /handlers.go
parent4f74722c14d18e78e172825961d7a65d25b41d3f (diff)
downloadalps-9617b412e8f1a2e3c3d112bbf5ece29bc2af37ee.tar.gz
alps-9617b412e8f1a2e3c3d112bbf5ece29bc2af37ee.zip
Make render data static
This makes sure fields filled by vanilla koushin keep the right type. A new Extra field allows plugins to attach their own data. This also makes it easier to write Go plugins, which would have trouble working with interface{}.
Diffstat (limited to 'handlers.go')
-rw-r--r--handlers.go53
1 files changed, 39 insertions, 14 deletions
diff --git a/handlers.go b/handlers.go
index 4615aa4..238b9ba 100644
--- a/handlers.go
+++ b/handlers.go
@@ -16,6 +16,14 @@ import (
"github.com/labstack/echo/v4"
)
+type MailboxRenderData struct {
+ Mailbox *imap.MailboxStatus
+ Mailboxes []*imap.MailboxInfo
+ Messages []imapMessage
+ PrevPage, NextPage int
+ Extra map[string]interface{}
+}
+
func handleGetMailbox(ectx echo.Context) error {
ctx := ectx.(*context)
@@ -58,12 +66,13 @@ func handleGetMailbox(ectx echo.Context) error {
nextPage = page + 1
}
- return ctx.Render(http.StatusOK, "mailbox.html", map[string]interface{}{
- "Mailbox": mbox,
- "Mailboxes": mailboxes,
- "Messages": msgs,
- "PrevPage": prevPage,
- "NextPage": nextPage,
+ return ctx.Render(http.StatusOK, "mailbox.html", &MailboxRenderData{
+ Mailbox: mbox,
+ Mailboxes: mailboxes,
+ Messages: msgs,
+ PrevPage: prevPage,
+ NextPage: nextPage,
+ Extra: make(map[string]interface{}),
})
}
@@ -108,6 +117,15 @@ func handleLogout(ectx echo.Context) error {
return ctx.Redirect(http.StatusFound, "/login")
}
+type MessageRenderData struct {
+ Mailbox *imap.MailboxStatus
+ Message *imapMessage
+ Body string
+ PartPath string
+ MailboxPage int
+ Extra map[string]interface{}
+}
+
func handleGetPart(ctx *context, raw bool) error {
mboxName, uid, err := parseMboxAndUid(ctx.Param("mbox"), ctx.Param("uid"))
if err != nil {
@@ -166,15 +184,21 @@ func handleGetPart(ctx *context, raw bool) error {
body = string(b)
}
- return ctx.Render(http.StatusOK, "message.html", map[string]interface{}{
- "Mailbox": mbox,
- "Message": msg,
- "Body": body,
- "PartPath": partPathString,
- "MailboxPage": (mbox.Messages - msg.SeqNum) / messagesPerPage,
+ return ctx.Render(http.StatusOK, "message.html", &MessageRenderData{
+ Mailbox: mbox,
+ Message: msg,
+ Body: body,
+ PartPath: partPathString,
+ MailboxPage: int(mbox.Messages-msg.SeqNum) / messagesPerPage,
+ Extra: make(map[string]interface{}),
})
}
+type ComposeRenderData struct {
+ Message *OutgoingMessage
+ Extra map[string]interface{}
+}
+
func handleCompose(ectx echo.Context) error {
ctx := ectx.(*context)
@@ -269,7 +293,8 @@ func handleCompose(ectx echo.Context) error {
return ctx.Redirect(http.StatusFound, "/mailbox/INBOX")
}
- return ctx.Render(http.StatusOK, "compose.html", map[string]interface{}{
- "Message": &msg,
+ return ctx.Render(http.StatusOK, "compose.html", &ComposeRenderData{
+ Message: &msg,
+ Extra: make(map[string]interface{}),
})
}