diff options
author | Daniel Baumann <daniel@debian.org> | 2024-10-18 20:33:49 +0200 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-12-12 23:57:56 +0100 |
commit | e68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch) | |
tree | 97775d6c13b0f416af55314eb6a89ef792474615 /services/mailer/mail_comment.go | |
parent | Initial commit. (diff) | |
download | forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip |
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'services/mailer/mail_comment.go')
-rw-r--r-- | services/mailer/mail_comment.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/services/mailer/mail_comment.go b/services/mailer/mail_comment.go new file mode 100644 index 0000000..1812441 --- /dev/null +++ b/services/mailer/mail_comment.go @@ -0,0 +1,63 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package mailer + +import ( + "context" + + activities_model "code.gitea.io/gitea/models/activities" + issues_model "code.gitea.io/gitea/models/issues" + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/container" + "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" +) + +// MailParticipantsComment sends new comment emails to repository watchers and mentioned people. +func MailParticipantsComment(ctx context.Context, c *issues_model.Comment, opType activities_model.ActionType, issue *issues_model.Issue, mentions []*user_model.User) error { + if setting.MailService == nil { + // No mail service configured + return nil + } + + content := c.Content + if c.Type == issues_model.CommentTypePullRequestPush { + content = "" + } + if err := mailIssueCommentToParticipants( + &mailCommentContext{ + Context: ctx, + Issue: issue, + Doer: c.Poster, + ActionType: opType, + Content: content, + Comment: c, + }, mentions); err != nil { + log.Error("mailIssueCommentToParticipants: %v", err) + } + return nil +} + +// MailMentionsComment sends email to users mentioned in a code comment +func MailMentionsComment(ctx context.Context, pr *issues_model.PullRequest, c *issues_model.Comment, mentions []*user_model.User) (err error) { + if setting.MailService == nil { + // No mail service configured + return nil + } + + visited := make(container.Set[int64], len(mentions)+1) + visited.Add(c.Poster.ID) + if err = mailIssueCommentBatch( + &mailCommentContext{ + Context: ctx, + Issue: pr.Issue, + Doer: c.Poster, + ActionType: activities_model.ActionCommentPull, + Content: c.Content, + Comment: c, + }, mentions, visited, true); err != nil { + log.Error("mailIssueCommentBatch: %v", err) + } + return nil +} |