diff options
Diffstat (limited to 'models/issue_mail.go')
-rw-r--r-- | models/issue_mail.go | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/models/issue_mail.go b/models/issue_mail.go index c10eec46..bdaec71b 100644 --- a/models/issue_mail.go +++ b/models/issue_mail.go @@ -10,6 +10,7 @@ import ( "github.com/Unknwon/com" "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/setting" ) @@ -18,6 +19,77 @@ func (issue *Issue) MailSubject() string { return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.Name, issue.Title, issue.Index) } +// mailerUser is a wrapper for satisfying mailer.User interface. +type mailerUser struct { + user *User +} + +func (this mailerUser) ID() int64 { + return this.user.ID +} + +func (this mailerUser) DisplayName() string { + return this.user.DisplayName() +} + +func (this mailerUser) Email() string { + return this.user.Email +} + +func (this mailerUser) GenerateActivateCode() string { + return this.user.GenerateActivateCode() +} + +func (this mailerUser) GenerateEmailActivateCode(email string) string { + return this.user.GenerateEmailActivateCode(email) +} + +func NewMailerUser(u *User) mailer.User { + return mailerUser{u} +} + +// mailerRepo is a wrapper for satisfying mailer.Repository interface. +type mailerRepo struct { + repo *Repository +} + +func (this mailerRepo) FullName() string { + return this.repo.FullName() +} + +func (this mailerRepo) HTMLURL() string { + return this.repo.HTMLURL() +} + +func (this mailerRepo) ComposeMetas() map[string]string { + return this.repo.ComposeMetas() +} + +func NewMailerRepo(repo *Repository) mailer.Repository { + return mailerRepo{repo} +} + +// mailerIssue is a wrapper for satisfying mailer.Issue interface. +type mailerIssue struct { + issue *Issue +} + +func (this mailerIssue) MailSubject() string { + return this.issue.MailSubject() +} + +func (this mailerIssue) Content() string { + return this.issue.Content +} + +func (this mailerIssue) HTMLURL() string { + return this.issue.HTMLURL() +} + +func NewMailerIssue(issue *Issue) mailer.Issue { + return mailerIssue{issue} +} + // mailIssueCommentToParticipants can be used for both new issue creation and comment. func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string) error { if !setting.Service.EnableNotifyMail { @@ -48,7 +120,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string) tos = append(tos, to.Email) names = append(names, to.Name) } - SendIssueCommentMail(issue, doer, tos) + mailer.SendIssueCommentMail(NewMailerIssue(issue), NewMailerRepo(issue.Repo), NewMailerUser(doer), tos) // Mail mentioned people and exclude watchers. names = append(names, doer.Name) @@ -60,7 +132,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string) tos = append(tos, mentions[i]) } - SendIssueMentionMail(issue, doer, GetUserEmailsByNames(tos)) + mailer.SendIssueMentionMail(NewMailerIssue(issue), NewMailerRepo(issue.Repo), NewMailerUser(doer), GetUserEmailsByNames(tos)) return nil } |