"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "services/mailer/mail_issue.go" between
gitea-1.13.1.tar.gz and gitea-1.13.2.tar.gz

About: Gitea allows to set up a self-hosted code hosting Git service (a fork of Gogs).

mail_issue.go  (gitea-1.13.1):mail_issue.go  (gitea-1.13.2)
skipping to change at line 12 skipping to change at line 12
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package mailer package mailer
import ( import (
"fmt" "fmt"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/references"
) )
func fallbackMailSubject(issue *models.Issue) string { func fallbackMailSubject(issue *models.Issue) string {
return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.FullName(), issue.Title, i ssue.Index) return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.FullName(), issue.Title, i ssue.Index)
} }
type mailCommentContext struct { type mailCommentContext struct {
Issue *models.Issue Issue *models.Issue
Doer *models.User Doer *models.User
ActionType models.ActionType ActionType models.ActionType
skipping to change at line 83 skipping to change at line 82
ids, err = models.GetRepoWatchersIDs(ctx.Issue.RepoID) ids, err = models.GetRepoWatchersIDs(ctx.Issue.RepoID)
if err != nil { if err != nil {
return fmt.Errorf("GetRepoWatchersIDs(%d): %v", ctx.Issue.RepoID, err) return fmt.Errorf("GetRepoWatchersIDs(%d): %v", ctx.Issue.RepoID, err)
} }
unfiltered = append(ids, unfiltered...) unfiltered = append(ids, unfiltered...)
visited := make(map[int64]bool, len(unfiltered)+len(mentions)+1) visited := make(map[int64]bool, len(unfiltered)+len(mentions)+1)
// Avoid mailing the doer // Avoid mailing the doer
visited[ctx.Doer.ID] = true visited[ctx.Doer.ID] = true
// =========== Mentions ===========
if err = mailIssueCommentBatch(ctx, mentions, visited, true); err != nil
{
return fmt.Errorf("mailIssueCommentBatch() mentions: %v", err)
}
// Avoid mailing explicit unwatched // Avoid mailing explicit unwatched
ids, err = models.GetIssueWatchersIDs(ctx.Issue.ID, false) ids, err = models.GetIssueWatchersIDs(ctx.Issue.ID, false)
if err != nil { if err != nil {
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, er r) return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, er r)
} }
for _, i := range ids { for _, i := range ids {
visited[i] = true visited[i] = true
} }
if err = mailIssueCommentBatch(ctx, unfiltered, visited, false); err != n il { if err = mailIssueCommentBatch(ctx, unfiltered, visited, false); err != n il {
return fmt.Errorf("mailIssueCommentBatch(): %v", err) return fmt.Errorf("mailIssueCommentBatch(): %v", err)
} }
// =========== Mentions ===========
if err = mailIssueCommentBatch(ctx, mentions, visited, true); err != nil
{
return fmt.Errorf("mailIssueCommentBatch() mentions: %v", err)
}
return nil return nil
} }
func mailIssueCommentBatch(ctx *mailCommentContext, ids []int64, visited map[int 64]bool, fromMention bool) error { func mailIssueCommentBatch(ctx *mailCommentContext, ids []int64, visited map[int 64]bool, fromMention bool) error {
const batchSize = 100 const batchSize = 100
for i := 0; i < len(ids); i += batchSize { for i := 0; i < len(ids); i += batchSize {
var last int var last int
if i+batchSize < len(ids) { if i+batchSize < len(ids) {
last = i + batchSize last = i + batchSize
} else { } else {
skipping to change at line 126 skipping to change at line 126
if _, ok := visited[id]; !ok { if _, ok := visited[id]; !ok {
unique = append(unique, id) unique = append(unique, id)
visited[id] = true visited[id] = true
} }
} }
recipients, err := models.GetMaileableUsersByIDs(unique, fromMent ion) recipients, err := models.GetMaileableUsersByIDs(unique, fromMent ion)
if err != nil { if err != nil {
return err return err
} }
checkUnit := models.UnitTypeIssues
if ctx.Issue.IsPull {
checkUnit = models.UnitTypePullRequests
}
// Make sure all recipients can still see the issue // Make sure all recipients can still see the issue
idx := 0 idx := 0
for _, r := range recipients { for _, r := range recipients {
if ctx.Issue.Repo.CheckUnitUser(r, models.UnitTypeIssues) { if ctx.Issue.Repo.CheckUnitUser(r, checkUnit) {
recipients[idx] = r recipients[idx] = r
idx++ idx++
} }
} }
recipients = recipients[:idx] recipients = recipients[:idx]
// TODO: Separate recipients by language for i18n mail templates // TODO: Separate recipients by language for i18n mail templates
tos := make([]string, len(recipients)) tos := make([]string, len(recipients))
for i := range recipients { for i := range recipients {
tos[i] = recipients[i].Email tos[i] = recipients[i].Email
} }
SendAsyncs(composeIssueCommentMessages(ctx, tos, fromMention, "is sue comments")) SendAsyncs(composeIssueCommentMessages(ctx, tos, fromMention, "is sue comments"))
} }
return nil return nil
} }
// MailParticipants sends new issue thread created emails to repository watchers // MailParticipants sends new issue thread created emails to repository watchers
// and mentioned people. // and mentioned people.
func MailParticipants(issue *models.Issue, doer *models.User, opType models.Acti func MailParticipants(issue *models.Issue, doer *models.User, opType models.Acti
onType) error { onType, mentions []*models.User) error {
return mailParticipants(models.DefaultDBContext(), issue, doer, opType) return mailParticipants(issue, doer, opType, mentions)
} }
func mailParticipants(ctx models.DBContext, issue *models.Issue, doer *models.Us func mailParticipants(issue *models.Issue, doer *models.User, opType models.Acti
er, opType models.ActionType) (err error) { onType, mentions []*models.User) (err error) {
rawMentions := references.FindAllMentionsMarkdown(issue.Content) mentionedIDs := make([]int64, len(mentions))
userMentions, err := issue.ResolveMentionsByVisibility(ctx, doer, rawMent for i, u := range mentions {
ions) mentionedIDs[i] = u.ID
if err != nil {
return fmt.Errorf("ResolveMentionsByVisibility [%d]: %v", issue.I
D, err)
}
if err = models.UpdateIssueMentions(ctx, issue.ID, userMentions); err !=
nil {
return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
}
mentions := make([]int64, len(userMentions))
for i, u := range userMentions {
mentions[i] = u.ID
} }
if err = mailIssueCommentToParticipants( if err = mailIssueCommentToParticipants(
&mailCommentContext{ &mailCommentContext{
Issue: issue, Issue: issue,
Doer: doer, Doer: doer,
ActionType: opType, ActionType: opType,
Content: issue.Content, Content: issue.Content,
Comment: nil, Comment: nil,
}, mentions); err != nil { }, mentionedIDs); err != nil {
log.Error("mailIssueCommentToParticipants: %v", err) log.Error("mailIssueCommentToParticipants: %v", err)
} }
return nil return nil
} }
 End of changes. 8 change blocks. 
28 lines changed or deleted 21 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)