FIX: notifications are missing under certain conditions

This simplifies the code for refreshing notification counts. It now
unconditionally looks up the user object which protects against stale objects
in memory.

This also removes a pile of conditional logic we no longer need.
This commit is contained in:
Sam Saffron 2019-10-23 16:09:55 +11:00
parent ab6a540fc4
commit 676c432b0f
1 changed files with 2 additions and 9 deletions

View File

@ -217,15 +217,8 @@ class Notification < ActiveRecord::Base
protected protected
def refresh_notification_count def refresh_notification_count
begin if user_id
if user.has_attribute?(:seen_notification_id) User.find_by(id: user_id)&.publish_notifications_state
user.notifications.reset
user.publish_notifications_state
else
User.find_by(id: user.id).publish_notifications_state
end
rescue ActiveRecord::RecordNotFound
# happens when we delete a user
end end
end end