diff --git a/app/assets/javascripts/discourse/views/header_view.js b/app/assets/javascripts/discourse/views/header_view.js index 80fd2620c1d..924cf2073e6 100644 --- a/app/assets/javascripts/discourse/views/header_view.js +++ b/app/assets/javascripts/discourse/views/header_view.js @@ -61,7 +61,6 @@ Discourse.HeaderView = Discourse.View.extend({ // We've seen all the notifications now headerView.set('currentUser.unread_notifications', 0); - headerView.set('currentUser.unread_private_messages', 0); headerView.showDropdown($('#user-notifications')); }); return false; diff --git a/app/models/user.rb b/app/models/user.rb index d798d9793bd..fae98a183a0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -267,12 +267,13 @@ class User < ActiveRecord::Base def reload @unread_notifications_by_type = nil + @unread_pms = nil super end def unread_private_messages - unread_notifications_by_type[Notification.types[:private_message]] || 0 + @unread_pms ||= notifications.where("read = false AND notification_type = ?", Notification.types[:private_message]).count end def unread_notifications @@ -280,7 +281,8 @@ class User < ActiveRecord::Base end def saw_notification_id(notification_id) - User.update_all ["seen_notification_id = ?", notification_id], ["seen_notification_id < ?", notification_id] + User.update_all ["seen_notification_id = ?", notification_id], + ["seen_notification_id < ?", notification_id] end def publish_notifications_state diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 42de7c5f776..d43b8995a64 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -161,6 +161,33 @@ describe Notification do end end + describe 'saw_regular_notification_id' do + it 'correctly updates the read state' do + user = Fabricate(:user) + + pm = Notification.create!(read: false, + user_id: user.id, + topic_id: 2, + post_number: 1, + data: '[]', + notification_type: Notification.types[:private_message]) + + other = Notification.create!(read: false, + user_id: user.id, + topic_id: 2, + post_number: 1, + data: '[]', + notification_type: Notification.types[:mentioned]) + + + user.saw_notification_id(other.id) + user.reload + + user.unread_notifications.should == 0 + user.unread_private_messages.should == 1 + end + end + describe 'mark_posts_read' do it "marks multiple posts as read if needed" do user = Fabricate(:user)