opening move, don't get rid of green notification till the pm is read

TODO a way to list all unread PMs
This commit is contained in:
Sam 2013-05-16 16:37:47 +10:00
parent 8b63c82f64
commit eb71e9de24
3 changed files with 31 additions and 3 deletions

View File

@ -61,7 +61,6 @@ Discourse.HeaderView = Discourse.View.extend({
// We've seen all the notifications now // We've seen all the notifications now
headerView.set('currentUser.unread_notifications', 0); headerView.set('currentUser.unread_notifications', 0);
headerView.set('currentUser.unread_private_messages', 0);
headerView.showDropdown($('#user-notifications')); headerView.showDropdown($('#user-notifications'));
}); });
return false; return false;

View File

@ -267,12 +267,13 @@ class User < ActiveRecord::Base
def reload def reload
@unread_notifications_by_type = nil @unread_notifications_by_type = nil
@unread_pms = nil
super super
end end
def unread_private_messages 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 end
def unread_notifications def unread_notifications
@ -280,7 +281,8 @@ class User < ActiveRecord::Base
end end
def saw_notification_id(notification_id) 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 end
def publish_notifications_state def publish_notifications_state

View File

@ -161,6 +161,33 @@ describe Notification do
end end
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 describe 'mark_posts_read' do
it "marks multiple posts as read if needed" do it "marks multiple posts as read if needed" do
user = Fabricate(:user) user = Fabricate(:user)