Move marking follow notifications as read to an after action

This commit is contained in:
Karina Kwiatek 2023-01-28 18:48:14 +01:00
parent 4dcc5dea55
commit 6e3bc40c57
1 changed files with 13 additions and 8 deletions

View File

@ -3,20 +3,13 @@
class UserController < ApplicationController class UserController < ApplicationController
before_action :set_user before_action :set_user
before_action :hidden_social_graph_redirect, only: %i[followers followings] before_action :hidden_social_graph_redirect, only: %i[followers followings]
after_action :mark_notification_as_read, only: %i[show]
def show def show
@answers = @user.cursored_answers(last_id: params[:last_id]) @answers = @user.cursored_answers(last_id: params[:last_id])
@answers_last_id = @answers.map(&:id).min @answers_last_id = @answers.map(&:id).min
@more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero? @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| respond_to do |format|
format.html format.html
format.turbo_stream format.turbo_stream
@ -66,6 +59,18 @@ class UserController < ApplicationController
private 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 def set_user
@user = User.where("LOWER(screen_name) = ?", params[:username].downcase).includes(:profile).first! @user = User.where("LOWER(screen_name) = ?", params[:username].downcase).includes(:profile).first!
end end