Skip to content

Commit

Permalink
問い合わせ通知に Newspaper を適応
Browse files Browse the repository at this point in the history
  • Loading branch information
goruchanchan committed Apr 8, 2024
1 parent af9367a commit 5e18955
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
10 changes: 1 addition & 9 deletions app/controllers/inquiries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
13 changes: 13 additions & 0 deletions app/models/inquiry_notifier.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions config/initializers/newspaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5e18955

Please sign in to comment.