Filter notifications by target type

This commit is contained in:
Karina Kwiatek 2022-07-21 16:30:04 +02:00 committed by Karina Kwiatek
parent f475cd0a0b
commit 0992d44aef
2 changed files with 13 additions and 10 deletions

View File

@ -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

View File

@ -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