From 80e312eb3b140392f0fa351add29baf02073baba Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Thu, 2 Feb 2023 10:38:41 +0100 Subject: [PATCH] Appease the dog overlords --- app/controllers/notifications_controller.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 8572f8ff..860dd3ec 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -16,11 +16,8 @@ class NotificationsController < ApplicationController def index @type = TYPE_MAPPINGS[params[:type]] || params[:type] @notifications = cursored_notifications_for(type: @type, last_id: params[:last_id]) - @notifications_last_id = @notifications.map(&:id).min - @more_data_available = !cursored_notifications_for(type: @type, last_id: @notifications_last_id, size: 1).count.zero? - @counters = Notification.where(recipient: current_user, new: true) - .group(:target_type) - .count(:target_type) + paginate_notifications + @counters = count_unread_by_type respond_to do |format| format.html @@ -30,6 +27,17 @@ class NotificationsController < ApplicationController private + def paginate_notifications + @notifications_last_id = @notifications.map(&:id).min + @more_data_available = !cursored_notifications_for(type: @type, last_id: @notifications_last_id, size: 1).count.zero? + end + + def count_unread_by_type + Notification.where(recipient: current_user, new: true) + .group(:target_type) + .count(:target_type) + end + def mark_notifications_as_read # using .dup to not modify @notifications -- useful in tests @notifications&.dup&.update_all(new: false) # rubocop:disable Rails/SkipsModelValidations