Skip to content

Avoid mailing users that have explicitly unwatched an issue (#10475) #10500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions models/issue_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ 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) {
func GetIssueWatchersIDs(issueID int64, watching bool) ([]int64, error) {
return getIssueWatchersIDs(x, issueID, watching)
}

func getIssueWatchersIDs(e Engine, issueID int64, watching bool) ([]int64, error) {
ids := make([]int64, 0, 64)
return ids, x.Table("issue_watch").
return ids, e.Table("issue_watch").
Where("issue_id=?", issueID).
And("is_watching = ?", true).
And("is_watching = ?", watching).
Select("user_id").
Find(&ids)
}
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