2019-09-24 07:02:49 +02:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package mailer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MailParticipantsComment sends new comment emails to repository watchers
|
|
|
|
// and mentioned people.
|
2021-01-02 18:04:02 +01:00
|
|
|
func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*models.User) error {
|
|
|
|
return mailParticipantsComment(c, opType, issue, mentions)
|
2019-09-24 07:02:49 +02:00
|
|
|
}
|
|
|
|
|
2021-01-02 18:04:02 +01:00
|
|
|
func mailParticipantsComment(c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*models.User) (err error) {
|
|
|
|
mentionedIDs := make([]int64, len(mentions))
|
|
|
|
for i, u := range mentions {
|
|
|
|
mentionedIDs[i] = u.ID
|
2019-10-10 18:45:11 +02:00
|
|
|
}
|
2021-05-31 08:17:34 +02:00
|
|
|
content := c.Content
|
|
|
|
if c.Type == models.CommentTypePullPush {
|
|
|
|
content = ""
|
|
|
|
}
|
2019-11-18 09:08:20 +01:00
|
|
|
if err = mailIssueCommentToParticipants(
|
|
|
|
&mailCommentContext{
|
|
|
|
Issue: issue,
|
|
|
|
Doer: c.Poster,
|
|
|
|
ActionType: opType,
|
2021-05-31 08:17:34 +02:00
|
|
|
Content: content,
|
2019-11-18 09:08:20 +01:00
|
|
|
Comment: c,
|
2021-01-02 18:04:02 +01:00
|
|
|
}, mentionedIDs); err != nil {
|
2019-11-07 14:34:28 +01:00
|
|
|
log.Error("mailIssueCommentToParticipants: %v", err)
|
2019-09-24 07:02:49 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-01-02 18:04:02 +01:00
|
|
|
|
|
|
|
// MailMentionsComment sends email to users mentioned in a code comment
|
|
|
|
func MailMentionsComment(pr *models.PullRequest, c *models.Comment, mentions []*models.User) (err error) {
|
|
|
|
mentionedIDs := make([]int64, len(mentions))
|
|
|
|
for i, u := range mentions {
|
|
|
|
mentionedIDs[i] = u.ID
|
|
|
|
}
|
|
|
|
visited := make(map[int64]bool, len(mentions)+1)
|
|
|
|
visited[c.Poster.ID] = true
|
|
|
|
if err = mailIssueCommentBatch(
|
|
|
|
&mailCommentContext{
|
|
|
|
Issue: pr.Issue,
|
|
|
|
Doer: c.Poster,
|
|
|
|
ActionType: models.ActionCommentPull,
|
|
|
|
Content: c.Content,
|
|
|
|
Comment: c,
|
|
|
|
}, mentionedIDs, visited, true); err != nil {
|
|
|
|
log.Error("mailIssueCommentBatch: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|