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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package mailer
  4. import (
  5. "context"
  6. activities_model "code.gitea.io/gitea/models/activities"
  7. issues_model "code.gitea.io/gitea/models/issues"
  8. user_model "code.gitea.io/gitea/models/user"
  9. "code.gitea.io/gitea/modules/container"
  10. "code.gitea.io/gitea/modules/log"
  11. "code.gitea.io/gitea/modules/setting"
  12. )
  13. // MailParticipantsComment sends new comment emails to repository watchers and mentioned people.
  14. func MailParticipantsComment(ctx context.Context, c *issues_model.Comment, opType activities_model.ActionType, issue *issues_model.Issue, mentions []*user_model.User) error {
  15. if setting.MailService == nil {
  16. // No mail service configured
  17. return nil
  18. }
  19. content := c.Content
  20. if c.Type == issues_model.CommentTypePullRequestPush {
  21. content = ""
  22. }
  23. if err := mailIssueCommentToParticipants(
  24. &mailCommentContext{
  25. Context: ctx,
  26. Issue: issue,
  27. Doer: c.Poster,
  28. ActionType: opType,
  29. Content: content,
  30. Comment: c,
  31. }, mentions); err != nil {
  32. log.Error("mailIssueCommentToParticipants: %v", err)
  33. }
  34. return nil
  35. }
  36. // MailMentionsComment sends email to users mentioned in a code comment
  37. func MailMentionsComment(ctx context.Context, pr *issues_model.PullRequest, c *issues_model.Comment, mentions []*user_model.User) (err error) {
  38. if setting.MailService == nil {
  39. // No mail service configured
  40. return nil
  41. }
  42. visited := make(container.Set[int64], len(mentions)+1)
  43. visited.Add(c.Poster.ID)
  44. if err = mailIssueCommentBatch(
  45. &mailCommentContext{
  46. Context: ctx,
  47. Issue: pr.Issue,
  48. Doer: c.Poster,
  49. ActionType: activities_model.ActionCommentPull,
  50. Content: c.Content,
  51. Comment: c,
  52. }, mentions, visited, true); err != nil {
  53. log.Error("mailIssueCommentBatch: %v", err)
  54. }
  55. return nil
  56. }