mirror of
https://gitlab.com/commento/commento.git
synced 2025-06-29 22:56:37 -04:00
everywhere: add email notifications
This commit is contained in:
63
api/email_notification_send.go
Normal file
63
api/email_notification_send.go
Normal file
@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
)
|
||||
|
||||
func emailNotificationSend(em string, kind string, notifications []emailNotification) {
|
||||
if len(notifications) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
e, err := emailGet(em)
|
||||
if err != nil {
|
||||
logger.Errorf("cannot get email: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
messages := []emailNotificationText{}
|
||||
for _, notification := range notifications {
|
||||
statement := `
|
||||
SELECT html
|
||||
FROM comments
|
||||
WHERE commentHex = $1;
|
||||
`
|
||||
row := db.QueryRow(statement, notification.CommentHex)
|
||||
|
||||
var html string
|
||||
if err = row.Scan(&html); err != nil {
|
||||
// the comment was deleted?
|
||||
// TODO: is this the only error?
|
||||
return
|
||||
}
|
||||
|
||||
messages = append(messages, emailNotificationText{
|
||||
emailNotification: notification,
|
||||
Html: template.HTML(html),
|
||||
})
|
||||
}
|
||||
|
||||
statement := `
|
||||
SELECT name
|
||||
FROM commenters
|
||||
WHERE email = $1;
|
||||
`
|
||||
row := db.QueryRow(statement, em)
|
||||
|
||||
var name string
|
||||
if err := row.Scan(&name); err != nil {
|
||||
// The moderator has probably not created a commenter account. Let's just
|
||||
// use their email as name.
|
||||
name = nameFromEmail(em)
|
||||
}
|
||||
|
||||
if err := emailNotificationPendingReset(em); err != nil {
|
||||
logger.Errorf("cannot reset after email notification: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := smtpEmailNotification(em, name, e.UnsubscribeSecretHex, messages, kind); err != nil {
|
||||
logger.Errorf("cannot send email notification: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user