2019-09-24 10:32:49 +05:30
|
|
|
// 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 (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
2019-10-14 03:59:10 +05:30
|
|
|
"code.gitea.io/gitea/modules/references"
|
2019-09-24 10:32:49 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
// MailParticipantsComment sends new comment emails to repository watchers
|
|
|
|
// and mentioned people.
|
|
|
|
func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue *models.Issue) error {
|
|
|
|
return mailParticipantsComment(models.DefaultDBContext(), c, opType, issue)
|
|
|
|
}
|
|
|
|
|
|
|
|
func mailParticipantsComment(ctx models.DBContext, c *models.Comment, opType models.ActionType, issue *models.Issue) (err error) {
|
2019-10-14 03:59:10 +05:30
|
|
|
rawMentions := references.FindAllMentionsMarkdown(c.Content)
|
2019-10-10 22:15:11 +05:30
|
|
|
userMentions, err := issue.ResolveMentionsByVisibility(ctx, c.Poster, rawMentions)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("ResolveMentionsByVisibility [%d]: %v", c.IssueID, err)
|
|
|
|
}
|
|
|
|
if err = models.UpdateIssueMentions(ctx, c.IssueID, userMentions); err != nil {
|
2019-09-24 10:32:49 +05:30
|
|
|
return fmt.Errorf("UpdateIssueMentions [%d]: %v", c.IssueID, err)
|
|
|
|
}
|
2019-11-18 13:38:20 +05:30
|
|
|
mentions := make([]int64, len(userMentions))
|
2019-10-10 22:15:11 +05:30
|
|
|
for i, u := range userMentions {
|
2019-11-18 13:38:20 +05:30
|
|
|
mentions[i] = u.ID
|
2019-10-10 22:15:11 +05:30
|
|
|
}
|
2019-11-18 13:38:20 +05:30
|
|
|
if err = mailIssueCommentToParticipants(
|
|
|
|
&mailCommentContext{
|
|
|
|
Issue: issue,
|
|
|
|
Doer: c.Poster,
|
|
|
|
ActionType: opType,
|
|
|
|
Content: c.Content,
|
|
|
|
Comment: c,
|
|
|
|
}, mentions); err != nil {
|
2019-11-07 19:04:28 +05:30
|
|
|
log.Error("mailIssueCommentToParticipants: %v", err)
|
2019-09-24 10:32:49 +05:30
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|