Improve sending overdue task reminders by only sending one for all overdue tasks
This commit is contained in:
@ -24,6 +24,8 @@ import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/api/pkg/mail"
|
||||
"code.vikunja.io/api/pkg/utils"
|
||||
|
||||
"github.com/yuin/goldmark"
|
||||
)
|
||||
|
||||
const mailTemplatePlain = `
|
||||
@ -54,10 +56,8 @@ const mailTemplateHTML = `
|
||||
{{ .Greeting }}
|
||||
</p>
|
||||
|
||||
{{ range $line := .IntroLines}}
|
||||
<p>
|
||||
{{ $line }}
|
||||
</p>
|
||||
{{ range $line := .IntroLinesHTML}}
|
||||
{{ $line }}
|
||||
{{ end }}
|
||||
|
||||
{{ if .ActionURL }}
|
||||
@ -67,10 +67,8 @@ const mailTemplateHTML = `
|
||||
</a>
|
||||
{{end}}
|
||||
|
||||
{{ range $line := .OutroLines}}
|
||||
<p>
|
||||
{{ $line }}
|
||||
</p>
|
||||
{{ range $line := .OutroLinesHTML}}
|
||||
{{ $line }}
|
||||
{{ end }}
|
||||
|
||||
{{ if .ActionURL }}
|
||||
@ -114,6 +112,32 @@ func RenderMail(m *Mail) (mailOpts *mail.Opts, err error) {
|
||||
data["Boundary"] = boundary
|
||||
data["FrontendURL"] = config.ServiceFrontendurl.GetString()
|
||||
|
||||
var introLinesHTML []templatehtml.HTML
|
||||
for _, line := range m.introLines {
|
||||
md := []byte(templatehtml.HTMLEscapeString(line))
|
||||
var buf bytes.Buffer
|
||||
err = goldmark.Convert(md, &buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//#nosec - the html is escaped few lines before
|
||||
introLinesHTML = append(introLinesHTML, templatehtml.HTML(buf.String()))
|
||||
}
|
||||
data["IntroLinesHTML"] = introLinesHTML
|
||||
|
||||
var outroLinesHTML []templatehtml.HTML
|
||||
for _, line := range m.outroLines {
|
||||
md := []byte(templatehtml.HTMLEscapeString(line))
|
||||
var buf bytes.Buffer
|
||||
err = goldmark.Convert(md, &buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//#nosec - the html is escaped few lines before
|
||||
outroLinesHTML = append(outroLinesHTML, templatehtml.HTML(buf.String()))
|
||||
}
|
||||
data["OutroLinesHTML"] = outroLinesHTML
|
||||
|
||||
err = plain.Execute(&plainContent, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -90,6 +90,7 @@ func TestRenderMail(t *testing.T) {
|
||||
Subject("Testmail").
|
||||
Greeting("Hi there,").
|
||||
Line("This is a line").
|
||||
Line("This **line** contains [a link](https://vikunja.io)").
|
||||
Line("And another one").
|
||||
Action("The action", "https://example.com").
|
||||
Line("This should be an outro line").
|
||||
@ -105,6 +106,8 @@ Hi there,
|
||||
|
||||
This is a line
|
||||
|
||||
This **line** contains [a link](https://vikunja.io)
|
||||
|
||||
And another one
|
||||
|
||||
The action:
|
||||
@ -132,13 +135,14 @@ And one more, because why not?
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
This is a line
|
||||
</p>
|
||||
<p>This is a line</p>
|
||||
|
||||
|
||||
<p>This <strong>line</strong> contains <a href="https://vikunja.io">a link</a></p>
|
||||
|
||||
|
||||
<p>And another one</p>
|
||||
|
||||
<p>
|
||||
And another one
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
@ -149,13 +153,11 @@ And one more, because why not?
|
||||
|
||||
|
||||
|
||||
<p>
|
||||
This should be an outro line
|
||||
</p>
|
||||
<p>This should be an outro line</p>
|
||||
|
||||
|
||||
<p>And one more, because why not?</p>
|
||||
|
||||
<p>
|
||||
And one more, because why not?
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user