Files
wanderer/db/util/email_templates.go
Flomp 9276690d60 Federation (#327)
* initial commit federation

* more federation

* more federation

* more federation

* completes follow, accept, undo

* add trail create activity

* process trail create activity

* more trail create activity

* adds missing endpoints

* adds update and delete activity

* adds comment activities

* adds activities back

* adds summit logs activities

* deletes follow counts table

* fixes migrations

* fixes migrations

* fixes migrations

* fixes migrations

* adds remote profiles

* ctd

* ctd

* we are getting closer...

* adds public summit logs

* fixes federated trails in lists

* adds remote lists

* adds list activites

* fixes lists

* adds notifications

* adds iri redirect

* fixes comments and summitlogs

* fixes follows and profiles

* adds asynchronous send

* fixes list search

* adds encryption key

* bug fixes

* fixes activity signing

* removes custon activity object types

* adds html editor

* fixes html editor

* fixes display issues on mastodon

* adds federated sharing

* finishes announcements

* fixes small summit log issues

* adds trail likes

* finalizes likes

* fixes images for komoot

* add disable federation option

* adds private profiles

* updates docs

* adds federated comments

* adds trail and comments actvitiypub routes

* adds mentions to editor

* adds mentions to trails, comments, summit logs

* updates theme

* updates theme

* update docs

* update docs

* updates docs

* fixes various frontend problems

* fixes activitypub follows api

* updates docs

* updates docs

---------

Co-authored-by: Christian Beutel <>
2025-06-21 10:09:22 +02:00

71 lines
2.0 KiB
Go

package util
import (
"bytes"
"errors"
t "html/template"
"github.com/pocketbase/pocketbase/tools/template"
)
type EmailData struct {
AppUrl string
RecipientName string
Content t.HTML
Link string
FollowerName string
}
var notificationTemplates = map[NotificationType]string{
TrailShare: "{{.Author}} has shared a trail with you: {{.trail}}.",
ListShare: "{{.Author}} has shared a list with you: {{.list}}.",
NewFollower: "Good news! You have a new follower: {{.Author}}.",
TrailComment: "{{.Author}} commented on your trail '{{.trail_name}}': '{{.comment}}'.",
SummitLogCreate: "{{.Author}} created a summit log on your trail '{{.trail_name}}'.",
TrailLike: "{{.Author}} liked your trail '{{.trail_name}}'.",
CommentMention: "{{.Author}} mentioned you in a comment.",
TrailMention: "{{.Author}} mentioned you in a trail.",
SummitLogMention: "{{.Author}} mentioned you in a summit log.",
}
func GenerateHTML(appUrl string, recipientName string, authorName string, notificationType NotificationType, metadata map[string]string) (string, error) {
registry := template.NewRegistry()
// Get custom content template for the notification type
customTemplate, exists := notificationTemplates[notificationType]
if !exists {
return "", errors.New("unknown notification type")
}
// Create content template with dynamic data
contentTmpl, err := t.New("content").Parse(customTemplate)
if err != nil {
return "", err
}
// Render the custom content with data
metadata["Author"] = authorName
var contentBuffer bytes.Buffer
err = contentTmpl.Execute(&contentBuffer, metadata)
if err != nil {
return "", err
}
// Assemble the final email with boilerplate and custom content
content := EmailData{
AppUrl: appUrl,
RecipientName: recipientName,
Content: t.HTML(contentBuffer.String()),
}
html, err := registry.LoadFiles(
"templates/mail/notification.html",
).Render(content)
if err != nil {
return "", err
}
return html, nil
}