本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.9KB

  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. }
上海开阖软件有限公司 沪ICP备12045867号-1