2022-07-30 09:29:32 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-12-04 22:02:23 -08:00
|
|
|
class AnswerController < ApplicationController
|
2023-02-07 13:59:48 -08:00
|
|
|
before_action :authenticate_user!, only: %i[pin unpin]
|
2023-02-06 23:32:25 -08:00
|
|
|
|
2014-12-04 22:02:23 -08:00
|
|
|
def show
|
2022-07-30 09:29:32 -07:00
|
|
|
@answer = Answer.includes(comments: %i[user smiles], question: [:user], smiles: [:user]).find(params[:id])
|
2014-12-12 09:54:17 -08:00
|
|
|
@display_all = true
|
2015-02-09 21:53:50 -08:00
|
|
|
|
|
|
|
if user_signed_in?
|
2022-07-30 09:14:48 -07:00
|
|
|
notif = Notification.where(type: "Notification::QuestionAnswered", target_id: @answer.id, recipient_id: current_user.id, new: true).first
|
2022-07-30 09:29:32 -07:00
|
|
|
notif&.update(new: false)
|
2022-07-30 09:14:48 -07:00
|
|
|
notif = Notification.where(type: "Notification::Commented", target_id: @answer.comments.pluck(:id), recipient_id: current_user.id, new: true)
|
2015-02-12 08:48:46 -08:00
|
|
|
notif.update_all(new: false) unless notif.empty?
|
2022-07-30 09:14:48 -07:00
|
|
|
notif = Notification.where(type: "Notification::Smiled", target_id: @answer.smiles.pluck(:id), recipient_id: current_user.id, new: true)
|
2015-02-12 08:48:46 -08:00
|
|
|
notif.update_all(new: false) unless notif.empty?
|
2022-07-30 09:14:48 -07:00
|
|
|
notif = Notification.where(type: "Notification::CommentSmiled", target_id: @answer.comment_smiles.pluck(:id), recipient_id: current_user.id, new: true)
|
2015-05-04 14:06:57 -07:00
|
|
|
notif.update_all(new: false) unless notif.empty?
|
2015-02-09 21:53:50 -08:00
|
|
|
end
|
2014-12-04 22:02:23 -08:00
|
|
|
end
|
2023-02-06 23:32:25 -08:00
|
|
|
|
|
|
|
def pin
|
|
|
|
answer = Answer.includes(:user).find(params[:id])
|
|
|
|
UseCase::Answer::Pin.call(user: current_user, answer:)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to(user_path(username: current_user.screen_name)) }
|
|
|
|
format.turbo_stream { render "pin", locals: { answer: } }
|
|
|
|
end
|
|
|
|
end
|
2023-02-06 23:36:29 -08:00
|
|
|
|
|
|
|
def unpin
|
|
|
|
answer = Answer.includes(:user).find(params[:id])
|
|
|
|
UseCase::Answer::Unpin.call(user: current_user, answer:)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to(user_path(username: current_user.screen_name)) }
|
|
|
|
format.turbo_stream { render "pin", locals: { answer: } }
|
|
|
|
end
|
|
|
|
end
|
2014-12-04 22:02:23 -08:00
|
|
|
end
|