mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-02-07 13:23:36 +01:00
Appease the dog overlords
This commit is contained in:
parent
691f72d0ce
commit
6089c57a20
7 changed files with 25 additions and 13 deletions
|
@ -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
|
||||||
|
|
|
@ -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,15 +35,15 @@ 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
|
||||||
|
|
||||||
def make_notification(recipient, target, notification_type)
|
def make_notification(recipient, target, notification_type)
|
||||||
n = notification_type.new(target: target,
|
n = notification_type.new(target: target,
|
||||||
recipient: recipient,
|
recipient: recipient,
|
||||||
new: true)
|
new: true)
|
||||||
n.save!
|
n.save!
|
||||||
n
|
n
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Notification::CommentSmiled < Notification
|
class Notification::CommentSmiled < Notification
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Notification::Commented < Notification
|
class Notification::Commented < Notification
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Notification::QuestionAnswered < Notification
|
class Notification::QuestionAnswered < Notification
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Notification::Smiled < Notification
|
class Notification::Smiled < Notification
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Notification::StartedFollowing < Notification
|
class Notification::StartedFollowing < Notification
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue