From c8d2b4404a078b309ecfc26409175320ed13805e Mon Sep 17 00:00:00 2001 From: goruchan Date: Wed, 3 Apr 2024 21:57:52 +0900 Subject: [PATCH] =?UTF-8?q?=E5=95=8F=E3=81=84=E5=90=88=E3=82=8F=E3=81=9B?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=81=AB=20Newspaper=20=E3=82=92=E9=81=A9?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/inquiries_controller.rb | 10 +--------- app/models/inquiry_notifier.rb | 13 +++++++++++++ config/initializers/newspaper.rb | 2 ++ 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 app/models/inquiry_notifier.rb diff --git a/app/controllers/inquiries_controller.rb b/app/controllers/inquiries_controller.rb index 6cc0da406fc..f0bd71c7ec3 100644 --- a/app/controllers/inquiries_controller.rb +++ b/app/controllers/inquiries_controller.rb @@ -13,7 +13,7 @@ def create result = valid_recaptcha?('inquiry') if result && @inquiry.save - notify_inquiry + Newspaper.publish(:came_inquiry, { inquiry: @inquiry }) InquiryMailer.incoming(@inquiry).deliver_later redirect_to new_inquiry_url, notice: 'お問い合わせを送信しました。' else @@ -27,12 +27,4 @@ def create def inquiry_params params.require(:inquiry).permit(:name, :email, :body, :privacy_policy) end - - def notify_inquiry - sender = User.find_by(login_name: 'pjord') - - User.admins.each do |receiver| - ActivityDelivery.with(inquiry: @inquiry, receiver:, sender:).notify(:came_inquiry) - end - end end diff --git a/app/models/inquiry_notifier.rb b/app/models/inquiry_notifier.rb new file mode 100644 index 00000000000..ca13c209e62 --- /dev/null +++ b/app/models/inquiry_notifier.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class InquiryNotifier + def call(payload) + inquiry = payload[:inquiry] + return if inquiry.nil? + + sender = User.find_by(login_name: 'pjord') + User.admins.each do |receiver| + ActivityDelivery.with(inquiry:, receiver:, sender:).notify(:came_inquiry) + end + end +end diff --git a/config/initializers/newspaper.rb b/config/initializers/newspaper.rb index 1dfe2d6590d..99ff755c67f 100644 --- a/config/initializers/newspaper.rb +++ b/config/initializers/newspaper.rb @@ -70,4 +70,6 @@ Newspaper.subscribe(:product_update, ProductUpdateNotifierForChecker.new) Newspaper.subscribe(:came_comment, CommentNotifier.new) Newspaper.subscribe(:came_comment_in_talk, CommentNotifierForAdmin.new) + + Newspaper.subscribe(:came_inquiry, InquiryNotifier.new) end