diff --git a/app/notifications/activity_notification.rb b/app/notifications/activity_notification.rb index 6762cd21d..efb5372c4 100644 --- a/app/notifications/activity_notification.rb +++ b/app/notifications/activity_notification.rb @@ -1,10 +1,5 @@ # frozen_string_literal: true -# To deliver this notification: -# -# ActivityNotification.with(post: @post).deliver_later(current_user) -# ActivityNotification.with(post: @post).deliver(current_user) - class ActivityNotification < BaseNotification include SearchHelper include GlobalActivitiesHelper @@ -13,15 +8,6 @@ class ActivityNotification < BaseNotification include ApplicationHelper include ActiveRecord::Sanitization::ClassMethods include Rails.application.routes.url_helpers - # Add your delivery methods - # - # deliver_by :email, mailer: "UserMailer" - # deliver_by :slack - # deliver_by :custom, class: "MyDeliveryMethod" - - # Add required params - # - # param :post def message params[:message] if params[:legacy] @@ -38,9 +24,6 @@ class ActivityNotification < BaseNotification def subject activity.subject unless params[:legacy] end - # def url - # post_path(params[:post]) - # end private diff --git a/app/notifications/base_notification.rb b/app/notifications/base_notification.rb index 2445d1889..6dc9c7f5d 100644 --- a/app/notifications/base_notification.rb +++ b/app/notifications/base_notification.rb @@ -2,10 +2,11 @@ class BaseNotification < Noticed::Base deliver_by :database, if: :database_notification? + deliver_by :email, mailer: 'NotificationMailer', method: :general_notification, if: :email_notification? def self.send_notifications(params, later: false) recipients_class = - "Recipients::#{NotificationExtends::NOTIFICATIONS_TYPES[subtype][:recipients_module]}".constantize + "Recipients::#{NotificationExtends::NOTIFICATIONS_TYPES[params[:type]][:recipients_module]}".constantize recipients_class.new(params).recipients.each do |recipient| if later with(params).deliver_later(recipient) @@ -15,7 +16,7 @@ class BaseNotification < Noticed::Base end end - def self.subtype + def subtype params[:type] end @@ -27,9 +28,13 @@ class BaseNotification < Noticed::Base recipient.notifications_settings.dig(notification_subgroup.to_s, 'in_app') end + def email_notification? + recipient.notifications_settings.dig(notification_subgroup.to_s, 'email') + end + def notification_subgroup NotificationExtends::NOTIFICATIONS_GROUPS.values.reduce({}, :merge).find do |_sg, n| - n.include?(self.class.subtype.to_sym) + n.include?(subtype.to_sym) end[0] end end diff --git a/app/notifications/low_stock_notification.rb b/app/notifications/low_stock_notification.rb index 5ec7bb774..4376acfdf 100644 --- a/app/notifications/low_stock_notification.rb +++ b/app/notifications/low_stock_notification.rb @@ -3,16 +3,18 @@ class LowStockNotification < BaseNotification def message I18n.t( - 'notifications.notification.item_low_stock_reminder_html', + 'notifications.content.item_low_stock_reminder.message_html', repository_row_name: subject.name ) end - def self.subtype + def subtype :item_low_stock_reminder end - def title; end + def title + I18n.t('notifications.content.item_low_stock_reminder.title_html') + end def subject RepositoryRow.find(params[:repository_row_id]) diff --git a/config/locales/en.yml b/config/locales/en.yml index c8b4f2a32..65cdc707a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3409,10 +3409,16 @@ en: repository_date_reminder: "Date reminder" other_smart_annotation: "You are mentioned (tagged) in any place of Scinote" other_team_invitation: "You are invited or removed from the team" - notification: - my_module_due_date_reminder_html: "Due date for %{my_module_name} is coming up" - item_low_stock_reminder_html: "Item %{repository_row_name} is running low" - item_date_reminder_html: "Date reminder for %{repository_row_name} is coming up in %{value} %{units}" + content: + my_module_due_date_reminder: + title_html: "Task due date reminder" + message_html: "Due date for %{my_module_name} is coming up" + item_low_stock_reminder: + title_html: "Item stock reminder" + message_html: "Item %{repository_row_name} is running low" + item_date_reminder: + title_html: "Item date reminder" + message_html: "Date reminder for %{repository_row_name} is coming up in %{value} %{units}" deliver: download_link: "Download link:" download_text: "Click the link to download the file."