2019-09-23 23:02:49 -06: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"
|
2021-08-12 01:26:33 -06:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2019-09-23 23:02:49 -06:00
|
|
|
)
|
|
|
|
|
2021-04-02 04:25:13 -06:00
|
|
|
// MailParticipantsComment sends new comment emails to repository watchers and mentioned people.
|
2021-01-02 10:04:02 -07:00
|
|
|
func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*models.User) error {
|
2021-08-12 01:26:33 -06:00
|
|
|
if setting.MailService == nil {
|
|
|
|
// No mail service configured
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-05-30 03:38:38 -06:00
|
|
|
content := c.Content
|
|
|
|
if c.Type == models.CommentTypePullPush {
|
|
|
|
content = ""
|
|
|
|
}
|
2021-04-02 04:25:13 -06:00
|
|
|
if err := mailIssueCommentToParticipants(
|
2019-11-18 01:08:20 -07:00
|
|
|
&mailCommentContext{
|
|
|
|
Issue: issue,
|
|
|
|
Doer: c.Poster,
|
|
|
|
ActionType: opType,
|
2021-05-30 03:38:38 -06:00
|
|
|
Content: content,
|
2019-11-18 01:08:20 -07:00
|
|
|
Comment: c,
|
2021-04-02 04:25:13 -06:00
|
|
|
}, mentions); err != nil {
|
2019-11-07 06:34:28 -07:00
|
|
|
log.Error("mailIssueCommentToParticipants: %v", err)
|
2019-09-23 23:02:49 -06:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-01-02 10:04:02 -07:00
|
|
|
|
|
|
|
// MailMentionsComment sends email to users mentioned in a code comment
|
|
|
|
func MailMentionsComment(pr *models.PullRequest, c *models.Comment, mentions []*models.User) (err error) {
|
2021-08-12 01:26:33 -06:00
|
|
|
if setting.MailService == nil {
|
|
|
|
// No mail service configured
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-02 10:04:02 -07:00
|
|
|
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,
|
2021-04-02 04:25:13 -06:00
|
|
|
}, mentions, visited, true); err != nil {
|
2021-01-02 10:04:02 -07:00
|
|
|
log.Error("mailIssueCommentBatch: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|