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

1234567891011121314151617181920212223242526272829303132333435363738
  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 err = mailIssueCommentToParticipants(issue, c.Poster, opType, c.Content, c, mentions); err != nil {
  30. log.Error("mailIssueCommentToParticipants: %v", err)
  31. }
  32. return nil
  33. }