mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08:00
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:
parent
8b63c82f64
commit
eb71e9de24
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user