summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-03-17 16:45:04 +0000
committerDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-03-17 16:45:04 +0000
commit9162e34bb078be9f4fb35b7e43f89c926dc3bcd8 (patch)
tree7d93fd0f30f83fb2fb2e502a4891aa2f1571fbc7 /app/services
parent409097bd7e0f5857cf0bc5462bd47484980ec787 (diff)
parent22fcb2f418ed6a2c7e68c0cd3ec2d414510ad4ec (diff)
downloadgitlab-ce-9162e34bb078be9f4fb35b7e43f89c926dc3bcd8.tar.gz
Merge branch 'issue_subscription' into 'master'
Subscription to issue/mr Fixes #1911 and #1909 ![joxi_screenshot_1426601822159](https://dev.gitlab.org/gitlab/gitlabhq/uploads/53021bc5783271322ab2dfba7598eaa3/joxi_screenshot_1426601822159.png) ![joxi_screenshot_1426601836423](https://dev.gitlab.org/gitlab/gitlabhq/uploads/244ff360fbd6f30980f8dad699400814/joxi_screenshot_1426601836423.png) See merge request !1702
Diffstat (limited to 'app/services')
-rw-r--r--app/services/notification_service.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb
index fb411c3e23d..848ed77ebf8 100644
--- a/app/services/notification_service.rb
+++ b/app/services/notification_service.rb
@@ -92,6 +92,8 @@ class NotificationService
#
def merge_mr(merge_request, current_user)
recipients = reject_muted_users([merge_request.author, merge_request.assignee], merge_request.target_project)
+ recipients = add_subscribed_users(recipients, merge_request)
+ recipients = reject_unsubscribed_users(recipients, merge_request)
recipients = recipients.concat(project_watchers(merge_request.target_project)).uniq
recipients.delete(current_user)
@@ -151,6 +153,10 @@ class NotificationService
# Reject mutes users
recipients = reject_muted_users(recipients, note.project)
+ recipients = add_subscribed_users(recipients, note.noteable)
+
+ recipients = reject_unsubscribed_users(recipients, note.noteable)
+
# Reject author
recipients.delete(note.author)
@@ -314,6 +320,27 @@ class NotificationService
end
end
+ def reject_unsubscribed_users(recipients, target)
+ return recipients unless target.respond_to? :subscriptions
+
+ recipients.reject do |user|
+ subscription = target.subscriptions.find_by_user_id(user.id)
+ subscription && !subscription.subscribed
+ end
+ end
+
+ def add_subscribed_users(recipients, target)
+ return recipients unless target.respond_to? :subscriptions
+
+ subscriptions = target.subscriptions
+
+ if subscriptions.any?
+ recipients + subscriptions.where(subscribed: true).map(&:user)
+ else
+ recipients
+ end
+ end
+
def new_resource_email(target, project, method)
recipients = build_recipients(target, project)
recipients.delete(target.author)
@@ -361,7 +388,9 @@ class NotificationService
recipients = reject_muted_users(recipients, project)
recipients = reject_mention_users(recipients, project)
+ recipients = add_subscribed_users(recipients, target)
recipients = recipients.concat(project_watchers(project)).uniq
+ recipients = reject_unsubscribed_users(recipients, target)
recipients
end