選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

mail_comment.go 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package mailer
  5. import (
  6. "fmt"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/references"
  10. )
  11. // MailParticipantsComment sends new comment emails to repository watchers
  12. // and mentioned people.
  13. func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue *models.Issue) error {
  14. return mailParticipantsComment(models.DefaultDBContext(), c, opType, issue)
  15. }
  16. func mailParticipantsComment(ctx models.DBContext, c *models.Comment, opType models.ActionType, issue *models.Issue) (err error) {
  17. rawMentions := references.FindAllMentionsMarkdown(c.Content)
  18. userMentions, err := issue.ResolveMentionsByVisibility(ctx, c.Poster, rawMentions)
  19. if err != nil {
  20. return fmt.Errorf("ResolveMentionsByVisibility [%d]: %v", c.IssueID, err)
  21. }
  22. if err = models.UpdateIssueMentions(ctx, c.IssueID, userMentions); err != nil {
  23. return fmt.Errorf("UpdateIssueMentions [%d]: %v", c.IssueID, err)
  24. }
  25. mentions := make([]string, len(userMentions))
  26. for i, u := range userMentions {
  27. mentions[i] = u.LowerName
  28. }
  29. if len(c.Content) > 0 {
  30. if err = mailIssueCommentToParticipants(issue, c.Poster, c.Content, c, mentions); err != nil {
  31. log.Error("mailIssueCommentToParticipants: %v", err)
  32. }
  33. }
  34. switch opType {
  35. case models.ActionCloseIssue:
  36. ct := fmt.Sprintf("Closed #%d.", issue.Index)
  37. if err = mailIssueCommentToParticipants(issue, c.Poster, ct, c, mentions); err != nil {
  38. log.Error("mailIssueCommentToParticipants: %v", err)
  39. }
  40. case models.ActionReopenIssue:
  41. ct := fmt.Sprintf("Reopened #%d.", issue.Index)
  42. if err = mailIssueCommentToParticipants(issue, c.Poster, ct, c, mentions); err != nil {
  43. log.Error("mailIssueCommentToParticipants: %v", err)
  44. }
  45. }
  46. return nil
  47. }