FIX: ensure 'notifications_state' is up to date after creating a notification

This commit is contained in:
Régis Hanol
2018-05-26 02:09:48 +02:00
parent cc0a5f4526
commit f988fa31aa
6 changed files with 61 additions and 66 deletions

View File

@ -59,22 +59,21 @@ class Notification < ActiveRecord::Base
def self.mark_posts_read(user, topic_id, post_numbers)
count = Notification
.where(user_id: user.id,
topic_id: topic_id,
post_number: post_numbers,
read: false)
.update_all("read = 't'")
.where(user_id: user.id)
.where(topic_id: topic_id)
.where(post_number: post_numbers)
.where(read: false)
.update_all(read: true)
if count > 0
user.publish_notifications_state
end
user.publish_notifications_state if count > 0
count
end
def self.read(user, notification_ids)
count = Notification.where(user_id: user.id)
count = Notification
.where(id: notification_ids)
.where(user_id: user.id)
.where(read: false)
.update_all(read: true)
@ -202,7 +201,7 @@ class Notification < ActiveRecord::Base
protected
def refresh_notification_count
user.publish_notifications_state
user.reload.publish_notifications_state
end
def send_email