mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: notify users about failing wakatime connection
This commit is contained in:
@ -16,12 +16,14 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
tplNamePasswordReset = "reset_password"
|
||||
tplNameImportNotification = "import_finished"
|
||||
tplNameReport = "report"
|
||||
subjectPasswordReset = "Wakapi - Password Reset"
|
||||
subjectImportNotification = "Wakapi - Data Import Finished"
|
||||
subjectReport = "Wakapi - Report from %s"
|
||||
tplNamePasswordReset = "reset_password"
|
||||
tplNameImportNotification = "import_finished"
|
||||
tplNameWakatimeFailureNotification = "wakatime_connection_failure"
|
||||
tplNameReport = "report"
|
||||
subjectPasswordReset = "Wakapi - Password Reset"
|
||||
subjectImportNotification = "Wakapi - Data Import Finished"
|
||||
subjectWakatimeFailureNotification = "Wakapi - WakaTime Connection Failure"
|
||||
subjectReport = "Wakapi - Report from %s"
|
||||
)
|
||||
|
||||
type SendingService interface {
|
||||
@ -64,6 +66,23 @@ func (m *MailService) SendPasswordReset(recipient *models.User, resetLink string
|
||||
return m.sendingService.Send(mail)
|
||||
}
|
||||
|
||||
func (m *MailService) SendWakatimeFailureNotification(recipient *models.User, numFailures int) error {
|
||||
tpl, err := getWakatimeFailureNotificationTemplate(WakatimeFailureNotificationNotificationTplData{
|
||||
PublicUrl: m.config.Server.PublicUrl,
|
||||
NumFailures: numFailures,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mail := &models.Mail{
|
||||
From: models.MailAddress(m.config.Mail.Sender),
|
||||
To: models.MailAddresses([]models.MailAddress{models.MailAddress(recipient.Email)}),
|
||||
Subject: subjectWakatimeFailureNotification,
|
||||
}
|
||||
mail.WithHTML(tpl.String())
|
||||
return m.sendingService.Send(mail)
|
||||
}
|
||||
|
||||
func (m *MailService) SendImportNotification(recipient *models.User, duration time.Duration, numHeartbeats int) error {
|
||||
tpl, err := getImportNotificationTemplate(ImportNotificationTplData{
|
||||
PublicUrl: m.config.Server.PublicUrl,
|
||||
@ -108,6 +127,18 @@ func getPasswordResetTemplate(data PasswordResetTplData) (*bytes.Buffer, error)
|
||||
return &rendered, nil
|
||||
}
|
||||
|
||||
func getWakatimeFailureNotificationTemplate(data WakatimeFailureNotificationNotificationTplData) (*bytes.Buffer, error) {
|
||||
tpl, err := loadTemplate(tplNameWakatimeFailureNotification)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var rendered bytes.Buffer
|
||||
if err := tpl.Execute(&rendered, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &rendered, nil
|
||||
}
|
||||
|
||||
func getImportNotificationTemplate(data ImportNotificationTplData) (*bytes.Buffer, error) {
|
||||
tpl, err := loadTemplate(tplNameImportNotification)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user