summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-03-16 15:35:48 +0200
committerValery Sizov <vsv2711@gmail.com>2015-03-16 16:51:49 +0200
commitf53683e67fa0db7b13d0dee977bc21206af7e0fd (patch)
tree023fb0f0f1c0c1bedeb21266ab941de9f4a2b8e8 /app/services
parent410d25c8ca8afabb25e5f89b36e3cfd09ffe6f87 (diff)
downloadgitlab-ce-f53683e67fa0db7b13d0dee977bc21206af7e0fd.tar.gz
fix specs
Diffstat (limited to 'app/services')
-rw-r--r--app/services/notification_service.rb29
1 files changed, 19 insertions, 10 deletions
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb
index e02418b7246..5ebde8fea84 100644
--- a/app/services/notification_service.rb
+++ b/app/services/notification_service.rb
@@ -151,6 +151,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)
@@ -315,12 +319,26 @@ class NotificationService
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 is true").map(&:user)
+ else
+ recipients
+ end
+ end
+
def new_resource_email(target, project, method)
recipients = build_recipients(target, project)
recipients.delete(target.author)
@@ -368,21 +386,12 @@ class NotificationService
recipients = reject_muted_users(recipients, project)
recipients = reject_mention_users(recipients, project)
- recipients = add_subscribed_users(recipients, project)
+ recipients = add_subscribed_users(recipients, target)
recipients = recipients.concat(project_watchers(project)).uniq
recipients = reject_unsubscribed_users(recipients, target)
recipients
end
- def add_subscribed_users(recipients, target)
- subscriptions = target.subscriptions
- if subscriptions.any?
- recipients.merge(subscriptions.where("subscribed is true").map(&:user))
- else
- recipients
- end
- end
-
def mailer
Notify.delay
end