mailIssueCommentToParticipants can be used for both new issue creation and comment. This functions sends two list of emails: 1. Repository watchers, users who participated in comments and the assignee. 2. Users who are not in 1. but get mentioned in current issue/comment.
(issue *Issue, doer *User, mentions []string)
| 106 | // 1. Repository watchers, users who participated in comments and the assignee. |
| 107 | // 2. Users who are not in 1. but get mentioned in current issue/comment. |
| 108 | func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string) error { |
| 109 | ctx := context.TODO() |
| 110 | |
| 111 | if !conf.User.EnableEmailNotification { |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | watchers, err := GetWatchers(issue.RepoID) |
| 116 | if err != nil { |
| 117 | return errors.Newf("GetWatchers [repo_id: %d]: %v", issue.RepoID, err) |
| 118 | } |
| 119 | participants, err := GetParticipantsByIssueID(issue.ID) |
| 120 | if err != nil { |
| 121 | return errors.Newf("GetParticipantsByIssueID [issue_id: %d]: %v", issue.ID, err) |
| 122 | } |
| 123 | |
| 124 | // In case the issue poster is not watching the repository, |
| 125 | // even if we have duplicated in watchers, can be safely filtered out. |
| 126 | if issue.PosterID != doer.ID { |
| 127 | participants = append(participants, issue.Poster) |
| 128 | } |
| 129 | |
| 130 | tos := make([]string, 0, len(watchers)) // List of email addresses |
| 131 | names := make([]string, 0, len(watchers)) |
| 132 | for i := range watchers { |
| 133 | if watchers[i].UserID == doer.ID { |
| 134 | continue |
| 135 | } |
| 136 | |
| 137 | to, err := Handle.Users().GetByID(ctx, watchers[i].UserID) |
| 138 | if err != nil { |
| 139 | return errors.Newf("GetUserByID [%d]: %v", watchers[i].UserID, err) |
| 140 | } |
| 141 | if to.IsOrganization() || !to.IsActive { |
| 142 | continue |
| 143 | } |
| 144 | |
| 145 | tos = append(tos, to.Email) |
| 146 | names = append(names, to.Name) |
| 147 | } |
| 148 | for i := range participants { |
| 149 | if participants[i].ID == doer.ID { |
| 150 | continue |
| 151 | } else if com.IsSliceContainsStr(names, participants[i].Name) { |
| 152 | continue |
| 153 | } |
| 154 | |
| 155 | tos = append(tos, participants[i].Email) |
| 156 | names = append(names, participants[i].Name) |
| 157 | } |
| 158 | if issue.Assignee != nil && issue.Assignee.ID != doer.ID { |
| 159 | if !com.IsSliceContainsStr(names, issue.Assignee.Name) { |
| 160 | tos = append(tos, issue.Assignee.Email) |
| 161 | names = append(names, issue.Assignee.Name) |
| 162 | } |
| 163 | } |
| 164 | email.SendIssueCommentMail(NewMailerIssue(issue), NewMailerRepo(issue.Repo), NewMailerUser(doer), tos) |
| 165 |
no test coverage detected