diff --git a/app/assets/javascripts/navigation.js b/app/assets/javascripts/navigation.js index b09968b81..64d81fcc8 100644 --- a/app/assets/javascripts/navigation.js +++ b/app/assets/javascripts/navigation.js @@ -31,6 +31,7 @@ animateSpinner($('.notifications-dropdown-header'), false); } }); + $('#count-notifications').hide(); }); } diff --git a/app/controllers/user_notifications_controller.rb b/app/controllers/user_notifications_controller.rb index 2f952703a..a74e0d44b 100644 --- a/app/controllers/user_notifications_controller.rb +++ b/app/controllers/user_notifications_controller.rb @@ -11,7 +11,7 @@ class UserNotificationsController < ApplicationController } end end - mark_seen_notification @recent_notifications + UserNotification.seen_by_user(current_user) end def unseen_notification @@ -25,12 +25,4 @@ class UserNotificationsController < ApplicationController end end end - - private - - def mark_seen_notification(notifications) - notifications.each do |notification| - notification.seen_by_user(current_user) - end - end end diff --git a/app/models/activity.rb b/app/models/activity.rb index 6cd65c165..8573251b1 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -74,6 +74,7 @@ class Activity < ActiveRecord::Base ) project.users.each do |project_user| + next if project_user == user UserNotification.create(notification: notification, user: project_user) end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 8e1fac34f..98b7e9c4e 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -10,11 +10,4 @@ class Notification < ActiveRecord::Base .pluck(:checked) .first end - - def seen_by_user(user) - user_notification = UserNotification.where(notification: self, user: user) - .first - user_notification.checked = true - user_notification.save - end end diff --git a/app/models/user_notification.rb b/app/models/user_notification.rb index 72e0b76f0..ea34f52a0 100644 --- a/app/models/user_notification.rb +++ b/app/models/user_notification.rb @@ -12,4 +12,11 @@ class UserNotification < ActiveRecord::Base def self.unseen_notification_count(user) where('user_id = ? AND checked = false', user.id).count end + + def self.seen_by_user(user) + where(user: user).map do |n| + n.checked = true + n.save + end + end end diff --git a/app/views/user_notifications/_recent_notifications.html.erb b/app/views/user_notifications/_recent_notifications.html.erb index 5920d106f..7847110f8 100644 --- a/app/views/user_notifications/_recent_notifications.html.erb +++ b/app/views/user_notifications/_recent_notifications.html.erb @@ -20,7 +20,7 @@