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