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.

mail_comment.go 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/markup"
  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. mentions := markup.FindAllMentions(c.Content)
  18. if err = models.UpdateIssueMentions(ctx, c.IssueID, mentions); err != nil {
  19. return fmt.Errorf("UpdateIssueMentions [%d]: %v", c.IssueID, err)
  20. }
  21. if len(c.Content) > 0 {
  22. if err = mailIssueCommentToParticipants(issue, c.Poster, c.Content, c, mentions); err != nil {
  23. log.Error("mailIssueCommentToParticipants: %v", err)
  24. }
  25. }
  26. switch opType {
  27. case models.ActionCloseIssue:
  28. ct := fmt.Sprintf("Closed #%d.", issue.Index)
  29. if err = mailIssueCommentToParticipants(issue, c.Poster, ct, c, mentions); err != nil {
  30. log.Error("mailIssueCommentToParticipants: %v", err)
  31. }
  32. case models.ActionReopenIssue:
  33. ct := fmt.Sprintf("Reopened #%d.", issue.Index)
  34. if err = mailIssueCommentToParticipants(issue, c.Poster, ct, c, mentions); err != nil {
  35. log.Error("mailIssueCommentToParticipants: %v", err)
  36. }
  37. }
  38. return nil
  39. }