Skip to content

Commit 50f2e90

Browse files
authored
[BugFix] Avoid mailing explicit unwatched (#10475) (#10500)
* [BugFix] Avoid mailing explicit unwatched (#10475)
1 parent 5d11ccc commit 50f2e90

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

models/issue_watch.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,18 @@ func getIssueWatch(e Engine, userID, issueID int64) (iw *IssueWatch, exists bool
6464
return
6565
}
6666

67-
// GetIssueWatchersIDs returns IDs of subscribers to a given issue id
67+
// GetIssueWatchersIDs returns IDs of subscribers or explicit unsubscribers to a given issue id
6868
// but avoids joining with `user` for performance reasons
6969
// User permissions must be verified elsewhere if required
70-
func GetIssueWatchersIDs(issueID int64) ([]int64, error) {
70+
func GetIssueWatchersIDs(issueID int64, watching bool) ([]int64, error) {
71+
return getIssueWatchersIDs(x, issueID, watching)
72+
}
73+
74+
func getIssueWatchersIDs(e Engine, issueID int64, watching bool) ([]int64, error) {
7175
ids := make([]int64, 0, 64)
72-
return ids, x.Table("issue_watch").
76+
return ids, e.Table("issue_watch").
7377
Where("issue_id=?", issueID).
74-
And("is_watching = ?", true).
78+
And("is_watching = ?", watching).
7579
Select("user_id").
7680
Find(&ids)
7781
}

services/mailer/mail_issue.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []int64) e
6262
unfiltered = append(unfiltered, ids...)
6363

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

8181
// Avoid mailing the doer
8282
visited[ctx.Doer.ID] = true
83+
// Avoid mailing explicit unwatched
84+
ids, err = models.GetIssueWatchersIDs(ctx.Issue.ID, false)
85+
if err != nil {
86+
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err)
87+
}
88+
for _, i := range ids {
89+
visited[i] = true
90+
}
8391

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

0 commit comments

Comments
 (0)