From 0992d44aefb21b136ce9dce366b05d4e0d36b9ec Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Thu, 21 Jul 2022 16:30:04 +0200 Subject: [PATCH] Filter notifications by target type --- app/controllers/notifications_controller.rb | 7 +++++-- app/models/notification.rb | 16 ++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 4ad39cce..722fbe0c 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -4,8 +4,11 @@ class NotificationsController < ApplicationController before_action :authenticate_user! TYPE_MAPPINGS = { - "smile" => "appendable::reaction", - "reaction" => "appendable::reaction" + "answer" => Notification::QuestionAnswered.name, + "comment" => Notification::Commented.name, + "commentsmile" => Notification::CommentSmiled.name, + "relationship" => Notification::StartedFollowing.name, + "smile" => Notification::Smiled.name, }.freeze def index diff --git a/app/models/notification.rb b/app/models/notification.rb index 78a54b5b..f7a19c05 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -13,7 +13,7 @@ class Notification < ApplicationRecord end def for_type(recipient, type, options={}) - self.where(options.merge!(recipient: recipient)).where('LOWER(target_type) = ?', type).order(:created_at).reverse_order + self.where(options.merge!(recipient: recipient)).where(type: type).order(:created_at).reverse_order end def notify(recipient, target) @@ -38,12 +38,12 @@ class Notification < ApplicationRecord private - def make_notification(recipient, target, notification_type) - n = notification_type.new(target: target, - recipient: recipient, - new: true) - n.save! - n - end + def make_notification(recipient, target, notification_type) + n = notification_type.new(target: target, + recipient: recipient, + new: true) + n.save! + n + end end end