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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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([]int64, len(userMentions))
  26. for i, u := range userMentions {
  27. mentions[i] = u.ID
  28. }
  29. if err = mailIssueCommentToParticipants(
  30. &mailCommentContext{
  31. Issue: issue,
  32. Doer: c.Poster,
  33. ActionType: opType,
  34. Content: c.Content,
  35. Comment: c,
  36. }, mentions); err != nil {
  37. log.Error("mailIssueCommentToParticipants: %v", err)
  38. }
  39. return nil
  40. }