Commit 9b0efdb7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Remove code duplication in notification_service.rb

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 616675b4
...@@ -276,35 +276,25 @@ class NotificationService ...@@ -276,35 +276,25 @@ class NotificationService
# Remove users with disabled notifications from array # Remove users with disabled notifications from array
# Also remove duplications and nil recipients # Also remove duplications and nil recipients
def reject_muted_users(users, project = nil) def reject_muted_users(users, project = nil)
users = users.to_a.compact.uniq reject_users(users, :disabled?, project)
users = users.reject(&:blocked?)
users.reject do |user|
next user.notification.disabled? unless project
member = project.project_members.find_by(user_id: user.id)
if !member && project.group
member = project.group.group_members.find_by(user_id: user.id)
end
# reject users who globally disabled notification and has no membership
next user.notification.disabled? unless member
# reject users who disabled notification in project
next true if member.notification.disabled?
# reject users who have N_GLOBAL in project and disabled in global settings
member.notification.global? && user.notification.disabled?
end
end end
# Remove users with notification level 'Mentioned' # Remove users with notification level 'Mentioned'
def reject_mention_users(users, project = nil) def reject_mention_users(users, project = nil)
reject_users(users, :mention?, project)
end
# Reject users which method_name from notification object returns true.
#
# Example:
# reject_users(users, :watch?, project)
#
def reject_users(users, method_name, project = nil)
users = users.to_a.compact.uniq users = users.to_a.compact.uniq
users = users.reject(&:blocked?)
users.reject do |user| users.reject do |user|
next user.notification.mention? unless project next user.notification.send(method_name) unless project
member = project.project_members.find_by(user_id: user.id) member = project.project_members.find_by(user_id: user.id)
...@@ -313,13 +303,13 @@ class NotificationService ...@@ -313,13 +303,13 @@ class NotificationService
end end
# reject users who globally set mention notification and has no membership # reject users who globally set mention notification and has no membership
next user.notification.mention? unless member next user.notification.send(method_name) unless member
# reject users who set mention notification in project # reject users who set mention notification in project
next true if member.notification.mention? next true if member.notification.send(method_name)
# reject users who have N_MENTION in project and disabled in global settings # reject users who have N_MENTION in project and disabled in global settings
member.notification.global? && user.notification.mention? member.notification.global? && user.notification.send(method_name)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment