2019-09-24 07:02:49 +02:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-09-24 07:02:49 +02:00
|
|
|
|
|
|
|
package mailer
|
|
|
|
|
|
|
|
import (
|
2022-01-20 00:26:57 +01:00
|
|
|
"context"
|
|
|
|
|
2022-08-25 04:31:57 +02:00
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
2022-06-13 11:37:59 +02:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-11-24 10:49:20 +01:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2022-10-12 07:18:26 +02:00
|
|
|
"code.gitea.io/gitea/modules/container"
|
2019-09-24 07:02:49 +02:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2021-08-12 09:26:33 +02:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2019-09-24 07:02:49 +02:00
|
|
|
)
|
|
|
|
|
2021-04-02 12:25:13 +02:00
|
|
|
// MailParticipantsComment sends new comment emails to repository watchers and mentioned people.
|
2022-08-25 04:31:57 +02:00
|
|
|
func MailParticipantsComment(ctx context.Context, c *issues_model.Comment, opType activities_model.ActionType, issue *issues_model.Issue, mentions []*user_model.User) error {
|
2021-08-12 09:26:33 +02:00
|
|
|
if setting.MailService == nil {
|
|
|
|
// No mail service configured
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-05-30 11:38:38 +02:00
|
|
|
content := c.Content
|
2022-06-13 11:37:59 +02:00
|
|
|
if c.Type == issues_model.CommentTypePullRequestPush {
|
2021-05-30 11:38:38 +02:00
|
|
|
content = ""
|
|
|
|
}
|
2021-04-02 12:25:13 +02:00
|
|
|
if err := mailIssueCommentToParticipants(
|
2019-11-18 09:08:20 +01:00
|
|
|
&mailCommentContext{
|
2022-01-20 00:26:57 +01:00
|
|
|
Context: ctx,
|
2019-11-18 09:08:20 +01:00
|
|
|
Issue: issue,
|
|
|
|
Doer: c.Poster,
|
|
|
|
ActionType: opType,
|
2021-05-30 11:38:38 +02:00
|
|
|
Content: content,
|
2019-11-18 09:08:20 +01:00
|
|
|
Comment: c,
|
2021-04-02 12:25:13 +02:00
|
|
|
}, mentions); 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
|
2022-06-13 11:37:59 +02:00
|
|
|
func MailMentionsComment(ctx context.Context, pr *issues_model.PullRequest, c *issues_model.Comment, mentions []*user_model.User) (err error) {
|
2021-08-12 09:26:33 +02:00
|
|
|
if setting.MailService == nil {
|
|
|
|
// No mail service configured
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-10-12 07:18:26 +02:00
|
|
|
visited := make(container.Set[int64], len(mentions)+1)
|
|
|
|
visited.Add(c.Poster.ID)
|
2021-01-02 18:04:02 +01:00
|
|
|
if err = mailIssueCommentBatch(
|
|
|
|
&mailCommentContext{
|
2022-01-20 00:26:57 +01:00
|
|
|
Context: ctx,
|
2021-01-02 18:04:02 +01:00
|
|
|
Issue: pr.Issue,
|
|
|
|
Doer: c.Poster,
|
2022-08-25 04:31:57 +02:00
|
|
|
ActionType: activities_model.ActionCommentPull,
|
2021-01-02 18:04:02 +01:00
|
|
|
Content: c.Content,
|
|
|
|
Comment: c,
|
2021-04-02 12:25:13 +02:00
|
|
|
}, mentions, visited, true); err != nil {
|
2021-01-02 18:04:02 +01:00
|
|
|
log.Error("mailIssueCommentBatch: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|