2019-09-24 14:02:49 +09: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 (
|
2022-01-20 08:26:57 +09:00
|
|
|
"context"
|
|
|
|
|
2019-09-24 14:02:49 +09:00
|
|
|
"code.gitea.io/gitea/models"
|
2021-11-24 18:49:20 +09:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2019-09-24 14:02:49 +09:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2021-08-12 16:26:33 +09:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2019-09-24 14:02:49 +09:00
|
|
|
)
|
|
|
|
|
2021-04-02 19:25:13 +09:00
|
|
|
// MailParticipantsComment sends new comment emails to repository watchers and mentioned people.
|
2022-01-20 08:26:57 +09:00
|
|
|
func MailParticipantsComment(ctx context.Context, c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*user_model.User) error {
|
2021-08-12 16:26:33 +09:00
|
|
|
if setting.MailService == nil {
|
|
|
|
// No mail service configured
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-05-30 18:38:38 +09:00
|
|
|
content := c.Content
|
2022-01-22 02:59:26 +09:00
|
|
|
if c.Type == models.CommentTypePullRequestPush {
|
2021-05-30 18:38:38 +09:00
|
|
|
content = ""
|
|
|
|
}
|
2021-04-02 19:25:13 +09:00
|
|
|
if err := mailIssueCommentToParticipants(
|
2019-11-18 17:08:20 +09:00
|
|
|
&mailCommentContext{
|
2022-01-20 08:26:57 +09:00
|
|
|
Context: ctx,
|
2019-11-18 17:08:20 +09:00
|
|
|
Issue: issue,
|
|
|
|
Doer: c.Poster,
|
|
|
|
ActionType: opType,
|
2021-05-30 18:38:38 +09:00
|
|
|
Content: content,
|
2019-11-18 17:08:20 +09:00
|
|
|
Comment: c,
|
2021-04-02 19:25:13 +09:00
|
|
|
}, mentions); err != nil {
|
2019-11-07 22:34:28 +09:00
|
|
|
log.Error("mailIssueCommentToParticipants: %v", err)
|
2019-09-24 14:02:49 +09:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-01-03 02:04:02 +09:00
|
|
|
|
|
|
|
// MailMentionsComment sends email to users mentioned in a code comment
|
2022-01-20 08:26:57 +09:00
|
|
|
func MailMentionsComment(ctx context.Context, pr *models.PullRequest, c *models.Comment, mentions []*user_model.User) (err error) {
|
2021-08-12 16:26:33 +09:00
|
|
|
if setting.MailService == nil {
|
|
|
|
// No mail service configured
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-03 02:04:02 +09:00
|
|
|
visited := make(map[int64]bool, len(mentions)+1)
|
|
|
|
visited[c.Poster.ID] = true
|
|
|
|
if err = mailIssueCommentBatch(
|
|
|
|
&mailCommentContext{
|
2022-01-20 08:26:57 +09:00
|
|
|
Context: ctx,
|
2021-01-03 02:04:02 +09:00
|
|
|
Issue: pr.Issue,
|
|
|
|
Doer: c.Poster,
|
|
|
|
ActionType: models.ActionCommentPull,
|
|
|
|
Content: c.Content,
|
|
|
|
Comment: c,
|
2021-04-02 19:25:13 +09:00
|
|
|
}, mentions, visited, true); err != nil {
|
2021-01-03 02:04:02 +09:00
|
|
|
log.Error("mailIssueCommentBatch: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|