summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-12-29 15:55:21 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-12-29 15:55:21 +0200
commitcf9573686586fafc199c6178b672f9ee617476d2 (patch)
tree21aaa5601ead31e3cacd8a3ccf7d2eed5a2e19de /app/services
parent6aec286fca169502edd4c643a6d2202a012fa142 (diff)
downloadgitlab-ce-cf9573686586fafc199c6178b672f9ee617476d2.tar.gz
New feature: add 'Mention' notification level
It does disable all emails expect system one or when you was @mentioned Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/services')
-rw-r--r--app/services/notification_service.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb
index d1aadd741e1..fb8f812dad8 100644
--- a/app/services/notification_service.rb
+++ b/app/services/notification_service.rb
@@ -144,6 +144,10 @@ class NotificationService
# Merge project watchers
recipients = recipients.concat(project_watchers(note.project)).compact.uniq
+ # Reject mention users unless mentioned in comment
+ recipients = reject_mention_users(recipients - note.mentioned_users, note.project)
+ recipients = recipients + note.mentioned_users
+
# Reject mutes users
recipients = reject_muted_users(recipients, note.project)
@@ -285,13 +289,39 @@ class NotificationService
end
end
+ # Remove users with notification level 'Mentioned'
+ def reject_mention_users(users, project = nil)
+ users = users.to_a.compact.uniq
+
+ users.reject do |user|
+ next user.notification.mention? unless project
+
+ tm = project.project_members.find_by(user_id: user.id)
+
+ if !tm && project.group
+ tm = project.group.group_members.find_by(user_id: user.id)
+ end
+
+ # reject users who globally set mention notification and has no membership
+ next user.notification.mention? unless tm
+
+ # reject users who set mention notification in project
+ next true if tm.notification.mention?
+
+ # reject users who have N_MENTION in project and disabled in global settings
+ tm.notification.global? && user.notification.mention?
+ end
+ end
+
def new_resource_email(target, project, method)
if target.respond_to?(:participants)
recipients = target.participants
else
recipients = []
end
+
recipients = reject_muted_users(recipients, project)
+ recipients = reject_mention_users(recipients, project)
recipients = recipients.concat(project_watchers(project)).uniq
recipients.delete(target.author)
@@ -302,6 +332,7 @@ class NotificationService
def close_resource_email(target, project, current_user, method)
recipients = reject_muted_users([target.author, target.assignee], project)
+ recipients = reject_mention_users(recipients, project)
recipients = recipients.concat(project_watchers(project)).uniq
recipients.delete(current_user)
@@ -320,6 +351,7 @@ class NotificationService
# reject users with disabled notifications
recipients = reject_muted_users(recipients, project)
+ recipients = reject_mention_users(recipients, project)
# Reject me from recipients if I reassign an item
recipients.delete(current_user)
@@ -331,6 +363,7 @@ class NotificationService
def reopen_resource_email(target, project, current_user, method, status)
recipients = reject_muted_users([target.author, target.assignee], project)
+ recipients = reject_mention_users(recipients, project)
recipients = recipients.concat(project_watchers(project)).uniq
recipients.delete(current_user)