Filter notifications by target type
This commit is contained in:
parent
f475cd0a0b
commit
0992d44aef
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue