2023-02-25 15:46:11 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module User::NotificationMethods
|
|
|
|
def unread_notification_count
|
2024-01-25 21:15:04 +01:00
|
|
|
Rails.cache.fetch(notification_cache_key, expires_in: 12.hours) do
|
2023-02-27 18:45:49 +01:00
|
|
|
count = Notification.for(self).where(new: true).count(:id)
|
|
|
|
|
|
|
|
# Returning +nil+ here in order to not display a counter
|
|
|
|
# at all when there aren't any notifications
|
2023-02-25 15:46:11 +01:00
|
|
|
return nil unless count.positive?
|
|
|
|
|
|
|
|
count
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-27 18:45:49 +01:00
|
|
|
def notification_cache_key = "#{cache_key}/unread_notification_count-#{notifications_updated_at}"
|
2023-05-05 16:45:42 +02:00
|
|
|
def notification_dropdown_cache_key = "#{cache_key}/notification_dropdown-#{notifications_updated_at}"
|
2023-02-25 15:46:11 +01:00
|
|
|
end
|