docbrown/app/labor/notification_counter.rb
Ben Halpern 115e52c748
Move follow and reaction aggregation into Notification model to avoid… (#1164)
* Move follow and reaction aggregation into Notification model to avoid re-compute

* Ugh. Fixing schema

* Update tests

* Skip some tests in notifications_spec
2018-11-20 15:00:21 -05:00

14 lines
287 B
Ruby

class NotificationCounter
def initialize(user)
@user = user
end
def unread_notification_count
return 0 if Rails.env.test?
@user.notifications.where(read: false).count
end
def set_to_zero
@user.notifications.where(read: false).update_all(read: true)
end
end