diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 35eda9f9..67ee3571 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base around_action :switch_locale before_action :banned? before_action :find_active_announcements + before_action :set_has_new_reports # check if user wants to read def switch_locale(&) @@ -48,6 +49,18 @@ class ApplicationController < ActionController::Base @active_announcements ||= Announcement.find_active end + def set_has_new_reports + return unless current_user&.mod? + + @has_new_reports = if current_user.last_reports_visit.nil? + true + else + Report.where(deleted: false) + .where("created_at > ?", current_user.last_reports_visit) + .count > 0 + end + end + include ApplicationHelper protected