diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 79be3630..ed054b8d 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -3,20 +3,13 @@ class UserController < ApplicationController before_action :set_user before_action :hidden_social_graph_redirect, only: %i[followers followings] + after_action :mark_notification_as_read, only: %i[show] def show @answers = @user.cursored_answers(last_id: params[:last_id]) @answers_last_id = @answers.map(&:id).min @more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero? - if user_signed_in? - notif = Notification.where(target_type: "Relationship", target_id: @user.active_follow_relationships.where(target_id: current_user.id).pluck(:id), recipient_id: current_user.id, new: true).first - unless notif.nil? - notif.new = false - notif.save - end - end - respond_to do |format| format.html format.turbo_stream @@ -66,6 +59,18 @@ class UserController < ApplicationController private + def mark_notification_as_read + return unless user_signed_in? + + Notification + .where( + target_type: "Relationship", + target_id: @user.active_follow_relationships.where(target_id: current_user.id).pluck(:id), + recipient_id: current_user.id, + new: true + ).update(new: false) + end + def set_user @user = User.where("LOWER(screen_name) = ?", params[:username].downcase).includes(:profile).first! end