Subtype fixes

This commit is contained in:
Martin Artnik 2023-11-24 14:58:46 +01:00
parent 3f338cafed
commit cc5aa5eaf5
3 changed files with 9 additions and 32 deletions

View file

@ -6,7 +6,7 @@ class BaseNotification < Noticed::Base
def self.send_notifications(params, later: false)
recipients_class =
"Recipients::#{NotificationExtends::NOTIFICATIONS_TYPES[params[:type]][:recipients_module]}".constantize
"Recipients::#{NotificationExtends::NOTIFICATIONS_TYPES[subtype || params[:type]][:recipients_module]}".constantize
recipients_class.new(params).recipients.each do |recipient|
if later
with(params).deliver_later(recipient)
@ -16,8 +16,10 @@ class BaseNotification < Noticed::Base
end
end
def self.subtype; end
def subtype
params[:type]
self.class.subtype || params[:type]
end
def subject; end

View file

@ -1,40 +1,15 @@
# frozen_string_literal: true
# To deliver this notification:
#
# GeneralNotification.with(post: @post).deliver_later(current_user)
# GeneralNotification.with(post: @post).deliver(current_user)
class GeneralNotification < BaseNotification
# Add your delivery methods
#
# deliver_by :email, mailer: "UserMailer"
# deliver_by :slack
# deliver_by :custom, class: "MyDeliveryMethod"
# Add required params
#
# param :post
# Define helper methods to make rendering easier.
#
def message
# if params[:legacy]
params[:message]
# else
# new logic
# end
end
def title
# if params[:legacy]
params[:title]
# else
# new logic
# end
end
#
# def url
# post_path(params[:post])
# end
def subtype
params[:type]
end
end

View file

@ -8,7 +8,7 @@ class LowStockNotification < BaseNotification
)
end
def subtype
def self.subtype
:item_low_stock_reminder
end