aboutsummaryrefslogtreecommitdiffstats
path: root/models/issues/issue.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issues/issue.go')
-rw-r--r--models/issues/issue.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/models/issues/issue.go b/models/issues/issue.go
index 5bdb60f7c0..49bc229c6b 100644
--- a/models/issues/issue.go
+++ b/models/issues/issue.go
@@ -1186,6 +1186,7 @@ type IssuesOptions struct { //nolint
PosterID int64
MentionedID int64
ReviewRequestedID int64
+ SubscriberID int64
MilestoneIDs []int64
ProjectID int64
ProjectBoardID int64
@@ -1299,6 +1300,10 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
applyReviewRequestedCondition(sess, opts.ReviewRequestedID)
}
+ if opts.SubscriberID > 0 {
+ applySubscribedCondition(sess, opts.SubscriberID)
+ }
+
if len(opts.MilestoneIDs) > 0 {
sess.In("issue.milestone_id", opts.MilestoneIDs)
}
@@ -1463,6 +1468,36 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64)
reviewRequestedID, ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest, reviewRequestedID)
}
+func applySubscribedCondition(sess *xorm.Session, subscriberID int64) *xorm.Session {
+ return sess.And(
+ builder.
+ NotIn("issue.id",
+ builder.Select("issue_id").
+ From("issue_watch").
+ Where(builder.Eq{"is_watching": false, "user_id": subscriberID}),
+ ),
+ ).And(
+ builder.Or(
+ builder.In("issue.id", builder.
+ Select("issue_id").
+ From("issue_watch").
+ Where(builder.Eq{"is_watching": true, "user_id": subscriberID}),
+ ),
+ builder.In("issue.id", builder.
+ Select("issue_id").
+ From("comment").
+ Where(builder.Eq{"poster_id": subscriberID}),
+ ),
+ builder.Eq{"issue.poster_id": subscriberID},
+ builder.In("issue.repo_id", builder.
+ Select("id").
+ From("watch").
+ Where(builder.Eq{"user_id": subscriberID, "mode": true}),
+ ),
+ ),
+ )
+}
+
// CountIssuesByRepo map from repoID to number of issues matching the options
func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
e := db.GetEngine(db.DefaultContext)