Appease the dog overlords
This commit is contained in:
parent
1b22872002
commit
08e5764bf3
|
@ -1,9 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class NotificationsController < ApplicationController
|
class NotificationsController < ApplicationController
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
|
||||||
TYPE_MAPPINGS = {
|
TYPE_MAPPINGS = {
|
||||||
'smile' => 'appendable::reaction',
|
"smile" => "appendable::reaction",
|
||||||
'reaction' => 'appendable::reaction',
|
"reaction" => "appendable::reaction"
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -24,9 +26,9 @@ class NotificationsController < ApplicationController
|
||||||
cursor_params = { last_id: last_id, size: size }.compact
|
cursor_params = { last_id: last_id, size: size }.compact
|
||||||
|
|
||||||
case type
|
case type
|
||||||
when 'all'
|
when "all"
|
||||||
Notification.cursored_for(current_user, **cursor_params)
|
Notification.cursored_for(current_user, **cursor_params)
|
||||||
when 'new'
|
when "new"
|
||||||
Notification.cursored_for(current_user, new: true, **cursor_params)
|
Notification.cursored_for(current_user, new: true, **cursor_params)
|
||||||
else
|
else
|
||||||
Notification.cursored_for_type(current_user, type, **cursor_params)
|
Notification.cursored_for_type(current_user, type, **cursor_params)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Appendable::Reaction < Appendable
|
class Appendable::Reaction < Appendable
|
||||||
|
# rubocop:disable Rails/SkipsModelValidations
|
||||||
after_create do
|
after_create do
|
||||||
Notification.notify parent.user, self unless parent.user == user
|
Notification.notify parent.user, self unless parent.user == user
|
||||||
user.increment! :smiled_count
|
user.increment! :smiled_count
|
||||||
|
@ -12,6 +13,7 @@ class Appendable::Reaction < Appendable
|
||||||
user.decrement! :smiled_count
|
user.decrement! :smiled_count
|
||||||
parent.decrement! :smile_count
|
parent.decrement! :smile_count
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Rails/SkipsModelValidations
|
||||||
|
|
||||||
def notification_type(*_args)
|
def notification_type(*_args)
|
||||||
Notifications::Smiled
|
Notifications::Smiled
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class MoveSmilesToAppendables < ActiveRecord::Migration[6.1]
|
class MoveSmilesToAppendables < ActiveRecord::Migration[6.1]
|
||||||
def up
|
def up
|
||||||
execute "INSERT INTO appendables (type, user_id, parent_id, parent_type, content, created_at, updated_at)
|
execute "INSERT INTO appendables (type, user_id, parent_id, parent_type, content, created_at, updated_at)
|
||||||
|
|
Loading…
Reference in New Issue