diff options
author | 6543 <6543@obermui.de> | 2021-04-02 12:25:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-02 11:25:13 +0100 |
commit | 80d6c6d7deb3f6a38ff6d09ec38ffb04de9da726 (patch) | |
tree | 8651abe082da4e920753f03ee4c37de1668ab826 /services/mailer/mail_release.go | |
parent | cc2d540092149166c9a0cef886b2e952ac9c75d7 (diff) | |
download | gitea-80d6c6d7deb3f6a38ff6d09ec38ffb04de9da726.tar.gz gitea-80d6c6d7deb3f6a38ff6d09ec38ffb04de9da726.zip |
[refactor] mailer service (#15072)
* Unexport SendUserMail
* Instead of "[]*models.User" or "[]string" lists infent "[]*MailRecipient" for mailer
* adopt
* code format
* TODOs for "i18n"
* clean
* no fallback for lang -> just use english
* lint
* exec testComposeIssueCommentMessage per lang and use only emails
* rm MailRecipient
* Dont reload from users from db if you alredy have in ram
* nits
* minimize diff
Signed-off-by: 6543 <6543@obermui.de>
* localize subjects
* linter ...
* Tr extend
* start tmpl edit ...
* Apply suggestions from code review
* use translation.Locale
* improve mailIssueCommentBatch
Signed-off-by: Andrew Thornton <art27@cantab.net>
* add i18n to datas
Signed-off-by: Andrew Thornton <art27@cantab.net>
* a comment
Co-authored-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/mailer/mail_release.go')
-rw-r--r-- | services/mailer/mail_release.go | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/services/mailer/mail_release.go b/services/mailer/mail_release.go index f278c853ae..22efe2f046 100644 --- a/services/mailer/mail_release.go +++ b/services/mailer/mail_release.go @@ -6,13 +6,13 @@ package mailer import ( "bytes" - "fmt" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/translation" ) const ( @@ -33,29 +33,40 @@ func MailNewRelease(rel *models.Release) { return } - tos := make([]string, 0, len(recipients)) - for _, to := range recipients { - if to.ID != rel.PublisherID { - tos = append(tos, to.Email) + langMap := make(map[string][]string) + for _, user := range recipients { + if user.ID != rel.PublisherID { + langMap[user.Language] = append(langMap[user.Language], user.Email) } } + for lang, tos := range langMap { + mailNewRelease(lang, tos, rel) + } +} + +func mailNewRelease(lang string, tos []string, rel *models.Release) { + locale := translation.NewLocale(lang) + rel.RenderedNote = markdown.RenderString(rel.Note, rel.Repo.Link(), rel.Repo.ComposeMetas()) - subject := fmt.Sprintf("%s in %s released", rel.TagName, rel.Repo.FullName()) + subject := locale.Tr("mail.release.new.subject", rel.TagName, rel.Repo.FullName()) mailMeta := map[string]interface{}{ - "Release": rel, - "Subject": subject, + "Release": rel, + "Subject": subject, + "i18n": locale, + "Language": locale.Language(), } var mailBody bytes.Buffer - if err = bodyTemplates.ExecuteTemplate(&mailBody, string(tplNewReleaseMail), mailMeta); err != nil { + // TODO: i18n templates? + if err := bodyTemplates.ExecuteTemplate(&mailBody, string(tplNewReleaseMail), mailMeta); err != nil { log.Error("ExecuteTemplate [%s]: %v", string(tplNewReleaseMail)+"/body", err) return } - msgs := make([]*Message, 0, len(recipients)) + msgs := make([]*Message, 0, len(tos)) publisherName := rel.Publisher.DisplayName() relURL := "<" + rel.HTMLURL() + ">" for _, to := range tos { |