Skip to content

Commit

Permalink
[BugFix] Avoid mailing explicit unwatched (#10475)
Browse files Browse the repository at this point in the history
* Avoid mailing explicit unwatched

* CI.restart()

* back to normal

Co-Authored-By: guillep2k <[email protected]>
  • Loading branch information
6543 and guillep2k authored Feb 27, 2020
1 parent 9a47611 commit a924a90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions models/issue_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ func getIssueWatch(e Engine, userID, issueID int64) (iw *IssueWatch, exists bool
return
}

// GetIssueWatchersIDs returns IDs of subscribers to a given issue id
// GetIssueWatchersIDs returns IDs of subscribers or explicit unsubscribers to a given issue id
// but avoids joining with `user` for performance reasons
// User permissions must be verified elsewhere if required
func GetIssueWatchersIDs(issueID int64) ([]int64, error) {
return getIssueWatchersIDs(x, issueID, true)
func GetIssueWatchersIDs(issueID int64, watching bool) ([]int64, error) {
return getIssueWatchersIDs(x, issueID, watching)
}

func getIssueWatchersIDs(e Engine, issueID int64, watching bool) ([]int64, error) {
Expand Down
10 changes: 9 additions & 1 deletion services/mailer/mail_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []int64) e
unfiltered = append(unfiltered, ids...)

// =========== Issue watchers ===========
ids, err = models.GetIssueWatchersIDs(ctx.Issue.ID)
ids, err = models.GetIssueWatchersIDs(ctx.Issue.ID, true)
if err != nil {
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err)
}
Expand All @@ -80,6 +80,14 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []int64) e

// Avoid mailing the doer
visited[ctx.Doer.ID] = true
// Avoid mailing explicit unwatched
ids, err = models.GetIssueWatchersIDs(ctx.Issue.ID, false)
if err != nil {
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err)
}
for _, i := range ids {
visited[i] = true
}

if err = mailIssueCommentBatch(ctx, unfiltered, visited, false); err != nil {
return fmt.Errorf("mailIssueCommentBatch(): %v", err)
Expand Down

0 comments on commit a924a90

Please sign in to comment.