mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-03-31 05:02:14 +02:00
Clean up marking notifications as read when viewing an answer
This commit is contained in:
parent
d7997db492
commit
0771c689ea
2 changed files with 13 additions and 12 deletions
|
@ -11,17 +11,7 @@ class AnswerController < ApplicationController
|
||||||
@answer = Answer.includes(comments: %i[user smiles], question: [:user], smiles: [:user]).find(params[:id])
|
@answer = Answer.includes(comments: %i[user smiles], question: [:user], smiles: [:user]).find(params[:id])
|
||||||
@subscribed = Subscription.where(user: current_user, answer: @answer).pluck(:id)
|
@subscribed = Subscription.where(user: current_user, answer: @answer).pluck(:id)
|
||||||
@display_all = true
|
@display_all = true
|
||||||
|
mark_notifications_as_read if user_signed_in?
|
||||||
if user_signed_in?
|
|
||||||
notif = Notification.where(type: "Notification::QuestionAnswered", target_id: @answer.id, recipient_id: current_user.id, new: true).first
|
|
||||||
notif&.update(new: false)
|
|
||||||
notif = Notification.where(type: "Notification::Commented", target_id: @answer.comments.pluck(:id), recipient_id: current_user.id, new: true)
|
|
||||||
notif.update_all(new: false) unless notif.empty?
|
|
||||||
notif = Notification.where(type: "Notification::Smiled", target_id: @answer.smiles.pluck(:id), recipient_id: current_user.id, new: true)
|
|
||||||
notif.update_all(new: false) unless notif.empty?
|
|
||||||
notif = Notification.where(type: "Notification::CommentSmiled", target_id: @answer.comment_smiles.pluck(:id), recipient_id: current_user.id, new: true)
|
|
||||||
notif.update_all(new: false) unless notif.empty?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def pin
|
def pin
|
||||||
|
@ -53,4 +43,15 @@ class AnswerController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def mark_notifications_as_read
|
||||||
|
Notification.where(recipient_id: current_user.id, new: true)
|
||||||
|
.and(Notification.where(type: "Notification::QuestionAnswered", target_id: @answer.id)
|
||||||
|
.or(Notification.where(type: "Notification::Commented", target_id: @answer.comments.pluck(:id)))
|
||||||
|
.or(Notification.where(type: "Notification::Smiled", target_id: @answer.smiles.pluck(:id)))
|
||||||
|
.or(Notification.where(type: "Notification::CommentSmiled", target_id: @answer.comment_smiles.pluck(:id))))
|
||||||
|
.update_all(new: false) # rubocop:disable Rails/SkipsModelValidations
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
- provide(:title, answer_title(@answer))
|
- provide(:title, answer_title(@answer))
|
||||||
- provide(:og, answer_opengraph(@answer))
|
- provide(:og, answer_opengraph(@answer))
|
||||||
.container-lg.container--main
|
.container-lg.container--main
|
||||||
= render 'answerbox', a: @answer, display_all: @display_all, subscribed_answer_ids: @subscribed
|
= render "answerbox", a: @answer, display_all: @display_all, subscribed_answer_ids: @subscribed
|
||||||
|
|
Loading…
Reference in a new issue