summaryrefslogtreecommitdiffstats
path: root/models/issue_mail.go
diff options
context:
space:
mode:
authorSandro Santilli <strk@kbt.io>2017-03-16 02:34:24 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2017-03-16 09:34:24 +0800
commit447c9b428f4cf50174ef7f3fbea56b5405f6bbf8 (patch)
tree9188395769273bd286e73ee940311216fce58073 /models/issue_mail.go
parentca1c3f1926eff992a2458f26cb24ed2f35265b05 (diff)
downloadgitea-447c9b428f4cf50174ef7f3fbea56b5405f6bbf8.tar.gz
gitea-447c9b428f4cf50174ef7f3fbea56b5405f6bbf8.zip
Send notifications to partecipants in issue comments (#1217)
* Send notifications to partecipants in issue comments Closes #1216 Includes test (still failing) * Do not include "labelers" to participants Fix test to expect what GetParticipants return
Diffstat (limited to 'models/issue_mail.go')
-rw-r--r--models/issue_mail.go26
1 files changed, 24 insertions, 2 deletions
diff --git a/models/issue_mail.go b/models/issue_mail.go
index 4b076606bf..4b6542ddb4 100644
--- a/models/issue_mail.go
+++ b/models/issue_mail.go
@@ -19,15 +19,27 @@ func (issue *Issue) mailSubject() string {
}
// mailIssueCommentToParticipants can be used for both new issue creation and comment.
+// This function sends two list of emails:
+// 1. Repository watchers and users who are participated in comments.
+// 2. Users who are not in 1. but get mentioned in current issue/comment.
func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string) error {
if !setting.Service.EnableNotifyMail {
return nil
}
- // Mail watchers.
watchers, err := GetWatchers(issue.RepoID)
if err != nil {
- return fmt.Errorf("GetWatchers [%d]: %v", issue.RepoID, err)
+ return fmt.Errorf("GetWatchers [repo_id: %d]: %v", issue.RepoID, err)
+ }
+ participants, err := GetParticipantsByIssueID(issue.ID)
+ if err != nil {
+ return fmt.Errorf("GetParticipantsByIssueID [issue_id: %d]: %v", issue.ID, err)
+ }
+
+ // In case the issue poster is not watching the repository,
+ // even if we have duplicated in watchers, can be safely filtered out.
+ if issue.PosterID != doer.ID {
+ participants = append(participants, issue.Poster)
}
tos := make([]string, 0, len(watchers)) // List of email addresses.
@@ -48,6 +60,16 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
tos = append(tos, to.Email)
names = append(names, to.Name)
}
+ for i := range participants {
+ if participants[i].ID == doer.ID {
+ continue
+ } else if com.IsSliceContainsStr(names, participants[i].Name) {
+ continue
+ }
+
+ tos = append(tos, participants[i].Email)
+ names = append(names, participants[i].Name)
+ }
SendIssueCommentMail(issue, doer, tos)
// Mail mentioned people and exclude watchers.