diff options
Diffstat (limited to 'modules/notification')
-rw-r--r-- | modules/notification/base/notifier.go | 2 | ||||
-rw-r--r-- | modules/notification/base/null.go | 2 | ||||
-rw-r--r-- | modules/notification/mail/mail.go | 10 | ||||
-rw-r--r-- | modules/notification/notification.go | 12 |
4 files changed, 20 insertions, 6 deletions
diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go index e44f3cc632..c74bb52014 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -21,7 +21,7 @@ type Notifier interface { NotifyNewIssue(*models.Issue) NotifyIssueChangeStatus(*models.User, *models.Issue, bool) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) - NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) + NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index 12be1999f9..9fb08884a1 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -83,7 +83,7 @@ func (*NullNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.I } // NotifyIssueChangeAssignee places a place holder function -func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) { +func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { } // NotifyIssueClearLabels places a place holder function diff --git a/modules/notification/mail/mail.go b/modules/notification/mail/mail.go index e1ae391f78..0900c6dcdf 100644 --- a/modules/notification/mail/mail.go +++ b/modules/notification/mail/mail.go @@ -5,6 +5,8 @@ package mail import ( + "fmt" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification/base" @@ -88,3 +90,11 @@ func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models log.Error("MailParticipants: %v", err) } } + +func (m *mailNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { + // mail only sent to added assignees and not self-assignee + if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() == models.EmailNotificationsEnabled { + ct := fmt.Sprintf("Assigned #%d.", issue.Index) + mailer.SendIssueAssignedMail(issue, doer, ct, comment, []string{assignee.Email}) + } +} diff --git a/modules/notification/notification.go b/modules/notification/notification.go index 06220ecb04..0f1b63cf67 100644 --- a/modules/notification/notification.go +++ b/modules/notification/notification.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/modules/notification/mail" "code.gitea.io/gitea/modules/notification/ui" "code.gitea.io/gitea/modules/notification/webhook" + "code.gitea.io/gitea/modules/setting" ) var ( @@ -24,9 +25,12 @@ func RegisterNotifier(notifier base.Notifier) { notifiers = append(notifiers, notifier) } -func init() { +// NewContext registers notification handlers +func NewContext() { RegisterNotifier(ui.NewNotifier()) - RegisterNotifier(mail.NewNotifier()) + if setting.Service.EnableNotifyMail { + RegisterNotifier(mail.NewNotifier()) + } RegisterNotifier(indexer.NewNotifier()) RegisterNotifier(webhook.NewNotifier()) } @@ -138,9 +142,9 @@ func NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent } // NotifyIssueChangeAssignee notifies change content to notifiers -func NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) { +func NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { for _, notifier := range notifiers { - notifier.NotifyIssueChangeAssignee(doer, issue, removed) + notifier.NotifyIssueChangeAssignee(doer, issue, assignee, removed, comment) } } |