From 54e072c98ccbdadd72063f742f417498d664ff35 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 30 Jul 2022 18:14:48 +0200 Subject: [PATCH] Use notification types instead of target types to clear them --- app/controllers/answer_controller.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/controllers/answer_controller.rb b/app/controllers/answer_controller.rb index f9398899..1743d2bf 100644 --- a/app/controllers/answer_controller.rb +++ b/app/controllers/answer_controller.rb @@ -4,17 +4,13 @@ class AnswerController < ApplicationController @display_all = true if user_signed_in? - notif = Notification.where(target_type: "Answer", target_id: @answer.id, recipient_id: current_user.id, new: true).first - unless notif.nil? - notif.new = false - notif.save - end - notif = Notification.where(target_type: "Comment", target_id: @answer.comments.pluck(:id), recipient_id: current_user.id, new: true) + notif = Notification.where(type: "Notification::QuestionAnswered", target_id: @answer.id, recipient_id: current_user.id, new: true).first + notif.update(new: false) unless notif.nil? + 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(target_type: "Smile", target_id: @answer.smiles.pluck(:id), recipient_id: current_user.id, new: true) + 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? - # @answer.comments.smiles throws - notif = Notification.where(target_type: "CommentSmile", target_id: @answer.comment_smiles.pluck(:id), recipient_id: current_user.id, new: true) + 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