From cc5aa5eaf5daea38618deac177bd371cbd9cee06 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Fri, 24 Nov 2023 14:58:46 +0100 Subject: [PATCH] Subtype fixes --- app/notifications/base_notification.rb | 6 ++-- app/notifications/general_notification.rb | 33 +++------------------ app/notifications/low_stock_notification.rb | 2 +- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/app/notifications/base_notification.rb b/app/notifications/base_notification.rb index 6dc9c7f5d..de93db9c3 100644 --- a/app/notifications/base_notification.rb +++ b/app/notifications/base_notification.rb @@ -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 diff --git a/app/notifications/general_notification.rb b/app/notifications/general_notification.rb index caa0b9717..38915252d 100644 --- a/app/notifications/general_notification.rb +++ b/app/notifications/general_notification.rb @@ -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 diff --git a/app/notifications/low_stock_notification.rb b/app/notifications/low_stock_notification.rb index 4376acfdf..e7d03d200 100644 --- a/app/notifications/low_stock_notification.rb +++ b/app/notifications/low_stock_notification.rb @@ -8,7 +8,7 @@ class LowStockNotification < BaseNotification ) end - def subtype + def self.subtype :item_low_stock_reminder end