Appease the dog overlords

This commit is contained in:
Karina Kwiatek 2022-07-21 16:56:05 +02:00 committed by Karina Kwiatek
parent 691f72d0ce
commit 6089c57a20
7 changed files with 25 additions and 13 deletions

View file

@ -8,7 +8,7 @@ class NotificationsController < ApplicationController
"comment" => Notification::Commented.name, "comment" => Notification::Commented.name,
"commentsmile" => Notification::CommentSmiled.name, "commentsmile" => Notification::CommentSmiled.name,
"relationship" => Notification::StartedFollowing.name, "relationship" => Notification::StartedFollowing.name,
"smile" => Notification::Smiled.name, "smile" => Notification::Smiled.name
}.freeze }.freeze
def index def index

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
class Notification < ApplicationRecord class Notification < ApplicationRecord
belongs_to :recipient, class_name: 'User' belongs_to :recipient, class_name: "User"
belongs_to :target, polymorphic: true belongs_to :target, polymorphic: true
class << self class << self
@ -8,12 +10,12 @@ class Notification < ApplicationRecord
define_cursor_paginator :cursored_for, :for define_cursor_paginator :cursored_for, :for
define_cursor_paginator :cursored_for_type, :for_type define_cursor_paginator :cursored_for_type, :for_type
def for(recipient, options={}) def for(recipient, options = {})
self.where(options.merge!(recipient: recipient)).order(:created_at).reverse_order where(options.merge!(recipient: recipient)).order(:created_at).reverse_order
end end
def for_type(recipient, type, options={}) def for_type(recipient, type, options = {})
self.where(options.merge!(recipient: recipient)).where(type: type).order(:created_at).reverse_order where(options.merge!(recipient: recipient)).where(type: type).order(:created_at).reverse_order
end end
def notify(recipient, target) def notify(recipient, target)
@ -33,7 +35,7 @@ class Notification < ApplicationRecord
return nil unless notif_type return nil unless notif_type
notif = Notification.find_by(recipient: recipient, target: target) notif = Notification.find_by(recipient: recipient, target: target)
notif.destroy unless notif.nil? notif&.destroy
end end
private private

View file

@ -1,2 +1,4 @@
# frozen_string_literal: true
class Notification::CommentSmiled < Notification class Notification::CommentSmiled < Notification
end end

View file

@ -1,2 +1,4 @@
# frozen_string_literal: true
class Notification::Commented < Notification class Notification::Commented < Notification
end end

View file

@ -1,2 +1,4 @@
# frozen_string_literal: true
class Notification::QuestionAnswered < Notification class Notification::QuestionAnswered < Notification
end end

View file

@ -1,2 +1,4 @@
# frozen_string_literal: true
class Notification::Smiled < Notification class Notification::Smiled < Notification
end end

View file

@ -1,2 +1,4 @@
# frozen_string_literal: true
class Notification::StartedFollowing < Notification class Notification::StartedFollowing < Notification
end end