Add or remove watchers from list based on their notification settings.
This commit is contained in:
parent
f4f0a7e03e
commit
ce30a56f33
1 changed files with 31 additions and 15 deletions
|
@ -178,22 +178,24 @@ class NotificationService
|
||||||
|
|
||||||
# Get project users with WATCH notification level
|
# Get project users with WATCH notification level
|
||||||
def project_watchers(project)
|
def project_watchers(project)
|
||||||
# Gather all user ids that have WATCH notification setting for project
|
# Gather all user that have WATCH notification setting for project and group
|
||||||
project_notification_uids = project_notification_list(project, Notification::N_WATCH)
|
project_uids, group_uids = project_and_group_watchers(project, Notification::N_WATCH)
|
||||||
|
|
||||||
# Gather all user ids that have WATCH notification setting for group
|
# Gather all user that have WATCH as their GLOBAL setting
|
||||||
group_notification_uids = group_notification_list(project, Notification::N_WATCH)
|
global_setting_project, global_setting_group = project_and_group_watchers(project, Notification::N_GLOBAL)
|
||||||
|
global_uids = [global_setting_project, global_setting_group].flatten.uniq
|
||||||
|
global_watchers_ids = User.where(id: global_uids, notification_level: Notification::N_WATCH).pluck(:id)
|
||||||
|
|
||||||
# Gather all user ids that have GLOBAL setting
|
# Select watchers based on what the project setting is
|
||||||
global_notification_uids = global_notification_list(project)
|
project_watchers, user_ids = select_watchers(global_watchers_ids, global_setting_project, project_uids)
|
||||||
|
|
||||||
project_and_group_uids = [project_notification_uids, group_notification_uids].flatten.uniq
|
# Select watchers based on what the group setting is
|
||||||
group_and_project_watchers = User.where(id: project_and_group_uids)
|
group_watchers, ids = select_watchers(user_ids, global_setting_group, group_uids)
|
||||||
|
|
||||||
# Find all users that have WATCH as their GLOBAL setting
|
project_watchers.concat(group_watchers.concat(ids)).uniq
|
||||||
global_watchers = User.where(id: global_notification_uids, notification_level: Notification::N_WATCH)
|
watchers = User.where(id: project_watchers)
|
||||||
|
|
||||||
[group_and_project_watchers, global_watchers].flatten.uniq
|
watchers.to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_notification_list(project, notification_level)
|
def project_notification_list(project, notification_level)
|
||||||
|
@ -208,11 +210,25 @@ class NotificationService
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def global_notification_list(project)
|
def select_watchers(user_ids, global_setting, setting)
|
||||||
|
watchers = []
|
||||||
|
user_ids.each do |i|
|
||||||
|
if setting.include?(i)
|
||||||
|
watchers << i
|
||||||
|
elsif global_setting.include?(i)
|
||||||
|
watchers << i
|
||||||
|
else
|
||||||
|
user_ids.delete(i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
[watchers, user_ids]
|
||||||
|
end
|
||||||
|
|
||||||
|
def project_and_group_watchers(project, notification_level)
|
||||||
[
|
[
|
||||||
project_notification_list(project, Notification::N_GLOBAL),
|
project_notification_list(project, notification_level),
|
||||||
group_notification_list(project, Notification::N_GLOBAL)
|
group_notification_list(project, notification_level)
|
||||||
].flatten
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove users with disabled notifications from array
|
# Remove users with disabled notifications from array
|
||||||
|
|
Loading…
Reference in a new issue