@@ -24,88 +24,88 @@ const MailBatchSize = 100 // batch size used in mailIssueCommentBatch
2424// This function sends two list of emails:
2525// 1. Repository watchers (except for WIP pull requests) and users who are participated in comments.
2626// 2. Users who are not in 1. but get mentioned in current issue/comment.
27- func mailIssueCommentToParticipants (ctx * mailCommentContext , mentions []* user_model.User ) error {
27+ func mailIssueCommentToParticipants (ctx context. Context , comment * mailComment , mentions []* user_model.User ) error {
2828 // Required by the mail composer; make sure to load these before calling the async function
29- if err := ctx .Issue .LoadRepo (ctx ); err != nil {
29+ if err := comment .Issue .LoadRepo (ctx ); err != nil {
3030 return fmt .Errorf ("LoadRepo: %w" , err )
3131 }
32- if err := ctx .Issue .LoadPoster (ctx ); err != nil {
32+ if err := comment .Issue .LoadPoster (ctx ); err != nil {
3333 return fmt .Errorf ("LoadPoster: %w" , err )
3434 }
35- if err := ctx .Issue .LoadPullRequest (ctx ); err != nil {
35+ if err := comment .Issue .LoadPullRequest (ctx ); err != nil {
3636 return fmt .Errorf ("LoadPullRequest: %w" , err )
3737 }
3838
3939 // Enough room to avoid reallocations
4040 unfiltered := make ([]int64 , 1 , 64 )
4141
4242 // =========== Original poster ===========
43- unfiltered [0 ] = ctx .Issue .PosterID
43+ unfiltered [0 ] = comment .Issue .PosterID
4444
4545 // =========== Assignees ===========
46- ids , err := issues_model .GetAssigneeIDsByIssue (ctx , ctx .Issue .ID )
46+ ids , err := issues_model .GetAssigneeIDsByIssue (ctx , comment .Issue .ID )
4747 if err != nil {
48- return fmt .Errorf ("GetAssigneeIDsByIssue(%d): %w" , ctx .Issue .ID , err )
48+ return fmt .Errorf ("GetAssigneeIDsByIssue(%d): %w" , comment .Issue .ID , err )
4949 }
5050 unfiltered = append (unfiltered , ids ... )
5151
5252 // =========== Participants (i.e. commenters, reviewers) ===========
53- ids , err = issues_model .GetParticipantsIDsByIssueID (ctx , ctx .Issue .ID )
53+ ids , err = issues_model .GetParticipantsIDsByIssueID (ctx , comment .Issue .ID )
5454 if err != nil {
55- return fmt .Errorf ("GetParticipantsIDsByIssueID(%d): %w" , ctx .Issue .ID , err )
55+ return fmt .Errorf ("GetParticipantsIDsByIssueID(%d): %w" , comment .Issue .ID , err )
5656 }
5757 unfiltered = append (unfiltered , ids ... )
5858
5959 // =========== Issue watchers ===========
60- ids , err = issues_model .GetIssueWatchersIDs (ctx , ctx .Issue .ID , true )
60+ ids , err = issues_model .GetIssueWatchersIDs (ctx , comment .Issue .ID , true )
6161 if err != nil {
62- return fmt .Errorf ("GetIssueWatchersIDs(%d): %w" , ctx .Issue .ID , err )
62+ return fmt .Errorf ("GetIssueWatchersIDs(%d): %w" , comment .Issue .ID , err )
6363 }
6464 unfiltered = append (unfiltered , ids ... )
6565
6666 // =========== Repo watchers ===========
6767 // Make repo watchers last, since it's likely the list with the most users
68- if ! (ctx .Issue .IsPull && ctx .Issue .PullRequest .IsWorkInProgress (ctx ) && ctx .ActionType != activities_model .ActionCreatePullRequest ) {
69- ids , err = repo_model .GetRepoWatchersIDs (ctx , ctx .Issue .RepoID )
68+ if ! (comment .Issue .IsPull && comment .Issue .PullRequest .IsWorkInProgress (ctx ) && comment .ActionType != activities_model .ActionCreatePullRequest ) {
69+ ids , err = repo_model .GetRepoWatchersIDs (ctx , comment .Issue .RepoID )
7070 if err != nil {
71- return fmt .Errorf ("GetRepoWatchersIDs(%d): %w" , ctx .Issue .RepoID , err )
71+ return fmt .Errorf ("GetRepoWatchersIDs(%d): %w" , comment .Issue .RepoID , err )
7272 }
7373 unfiltered = append (ids , unfiltered ... )
7474 }
7575
7676 visited := make (container.Set [int64 ], len (unfiltered )+ len (mentions )+ 1 )
7777
7878 // Avoid mailing the doer
79- if ctx .Doer .EmailNotificationsPreference != user_model .EmailNotificationsAndYourOwn && ! ctx .ForceDoerNotification {
80- visited .Add (ctx .Doer .ID )
79+ if comment .Doer .EmailNotificationsPreference != user_model .EmailNotificationsAndYourOwn && ! comment .ForceDoerNotification {
80+ visited .Add (comment .Doer .ID )
8181 }
8282
8383 // =========== Mentions ===========
84- if err = mailIssueCommentBatch (ctx , mentions , visited , true ); err != nil {
84+ if err = mailIssueCommentBatch (ctx , comment , mentions , visited , true ); err != nil {
8585 return fmt .Errorf ("mailIssueCommentBatch() mentions: %w" , err )
8686 }
8787
8888 // Avoid mailing explicit unwatched
89- ids , err = issues_model .GetIssueWatchersIDs (ctx , ctx .Issue .ID , false )
89+ ids , err = issues_model .GetIssueWatchersIDs (ctx , comment .Issue .ID , false )
9090 if err != nil {
91- return fmt .Errorf ("GetIssueWatchersIDs(%d): %w" , ctx .Issue .ID , err )
91+ return fmt .Errorf ("GetIssueWatchersIDs(%d): %w" , comment .Issue .ID , err )
9292 }
9393 visited .AddMultiple (ids ... )
9494
9595 unfilteredUsers , err := user_model .GetMailableUsersByIDs (ctx , unfiltered , false )
9696 if err != nil {
9797 return err
9898 }
99- if err = mailIssueCommentBatch (ctx , unfilteredUsers , visited , false ); err != nil {
99+ if err = mailIssueCommentBatch (ctx , comment , unfilteredUsers , visited , false ); err != nil {
100100 return fmt .Errorf ("mailIssueCommentBatch(): %w" , err )
101101 }
102102
103103 return nil
104104}
105105
106- func mailIssueCommentBatch (ctx * mailCommentContext , users []* user_model.User , visited container.Set [int64 ], fromMention bool ) error {
106+ func mailIssueCommentBatch (ctx context. Context , comment * mailComment , users []* user_model.User , visited container.Set [int64 ], fromMention bool ) error {
107107 checkUnit := unit .TypeIssues
108- if ctx .Issue .IsPull {
108+ if comment .Issue .IsPull {
109109 checkUnit = unit .TypePullRequests
110110 }
111111
@@ -129,7 +129,7 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, vi
129129 }
130130
131131 // test if this user is allowed to see the issue/pull
132- if ! access_model .CheckRepoUnitUser (ctx , ctx .Issue .Repo , user , checkUnit ) {
132+ if ! access_model .CheckRepoUnitUser (ctx , comment .Issue .Repo , user , checkUnit ) {
133133 continue
134134 }
135135
@@ -141,7 +141,7 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, vi
141141 // working backwards from the last (possibly) incomplete batch. If len(receivers) can be 0 this
142142 // starting condition will need to be changed slightly
143143 for i := ((len (receivers ) - 1 ) / MailBatchSize ) * MailBatchSize ; i >= 0 ; i -= MailBatchSize {
144- msgs , err := composeIssueCommentMessages (ctx , lang , receivers [i :], fromMention , "issue comments" )
144+ msgs , err := composeIssueCommentMessages (ctx , comment , lang , receivers [i :], fromMention , "issue comments" )
145145 if err != nil {
146146 return err
147147 }
@@ -168,9 +168,8 @@ func MailParticipants(ctx context.Context, issue *issues_model.Issue, doer *user
168168 content = ""
169169 }
170170 forceDoerNotification := opType == activities_model .ActionAutoMergePullRequest
171- if err := mailIssueCommentToParticipants (
172- & mailCommentContext {
173- Context : ctx ,
171+ if err := mailIssueCommentToParticipants (ctx ,
172+ & mailComment {
174173 Issue : issue ,
175174 Doer : doer ,
176175 ActionType : opType ,
@@ -205,8 +204,7 @@ func SendIssueAssignedMail(ctx context.Context, issue *issues_model.Issue, doer
205204 }
206205
207206 for lang , tos := range langMap {
208- msgs , err := composeIssueCommentMessages (& mailCommentContext {
209- Context : ctx ,
207+ msgs , err := composeIssueCommentMessages (ctx , & mailComment {
210208 Issue : issue ,
211209 Doer : doer ,
212210 ActionType : activities_model .ActionType (0 ),
0 commit comments