diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-06-17 06:17:20 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-06-17 06:17:20 +0300 |
commit | 33c61bd461d21dbb79db18e0c2424f53120e83c0 (patch) | |
tree | 2b0d60fe8b8a9c132c8c25f63131d333821f876e /app/services/notification_service.rb | |
parent | 24f5f071dcce529a3fbbc887ebce7bfc56353361 (diff) | |
parent | f82ab42d0534950c1ceb458e0152f329df80ae9d (diff) |
Re-use notifications dropdown/modal for user profile
Diffstat (limited to 'app/services/notification_service.rb')
-rw-r--r-- | app/services/notification_service.rb | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 5bdefcc8116..e455101f526 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -159,7 +159,7 @@ class NotificationService recipients = add_project_watchers(recipients, note.project) # Merge project with custom notification - recipients = add_project_custom_notifications(recipients, note.project, :new_note) + recipients = add_custom_notifications(recipients, note.project, :new_note) # Reject users with Mention notification level, except those mentioned in _this_ note. recipients = reject_mention_users(recipients - mentioned_users, note.project) @@ -277,12 +277,20 @@ class NotificationService protected # Get project/group users with CUSTOM notification level - def add_project_custom_notifications(recipients, project, action) + def add_custom_notifications(recipients, project, action) user_ids = [] + # Users with a notification setting on group or project user_ids += notification_settings_for(project, :custom, action) user_ids += notification_settings_for(project.group, :custom, action) + # Users with global level custom + users_with_project_level_global = notification_settings_for(project, :global) + users_with_group_level_global = notification_settings_for(project.group, :global) + + global_users_ids = users_with_project_level_global.concat(users_with_group_level_global) + user_ids += users_with_global_level_custom(global_users_ids, action) + recipients.concat(User.find(user_ids)) end @@ -291,7 +299,8 @@ class NotificationService project_members = notification_settings_for(project) users_with_project_level_global = notification_settings_for(project, :global) - users_with_group_level_global = notification_settings_for(project, :global) + users_with_group_level_global = notification_settings_for(project.group, :global) + users = users_with_global_level_watch([users_with_project_level_global, users_with_group_level_global].flatten.uniq) users_with_project_setting = select_project_member_setting(project, users_with_project_level_global, users) @@ -313,11 +322,21 @@ class NotificationService end def users_with_global_level_watch(ids) + settings_with_global_level_of(:watch, ids).pluck(:user_id) + end + + def users_with_global_level_custom(ids, action) + settings = settings_with_global_level_of(:custom, ids) + settings = settings.select { |setting| setting.events[action] } + settings.map(&:user_id) + end + + def settings_with_global_level_of(level, ids) NotificationSetting.where( user_id: ids, source_type: nil, - level: NotificationSetting.levels[:watch] - ).pluck(:user_id) + level: NotificationSetting.levels[level] + ) end # Build a list of users based on project notifcation settings @@ -497,7 +516,8 @@ class NotificationService recipients = target.participants(current_user) recipients = add_project_watchers(recipients, project) - recipients = add_project_custom_notifications(recipients, project, custom_action) + + recipients = add_custom_notifications(recipients, project, custom_action) recipients = reject_mention_users(recipients, project) recipients = recipients.uniq |