diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 4860a652..95c5be32 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -89,7 +89,9 @@ class PostsController < ApplicationController post_status_id: @post.post_status_id ) - UserMailer.notify_followers_of_post_status_change(post: @post).deliver_later + @post.followers.each do |follower| + UserMailer.notify_follower_of_post_status_change(post: @post, follower: follower).deliver_later + end end render json: @post diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 44595782..c34e8c08 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,9 +1,6 @@ class UserMailer < ApplicationMailer - layout 'user_mailer' - def notify_post_owner(comment:) - @tenant = comment.tenant - Current.tenant = @tenant + Current.tenant = comment.tenant @comment = comment @user = comment.post.user @@ -14,8 +11,7 @@ class UserMailer < ApplicationMailer end def notify_comment_owner(comment:) - @tenant = comment.tenant - Current.tenant = @tenant + Current.tenant = comment.tenant @comment = comment @user = comment.parent.user @@ -25,25 +21,25 @@ class UserMailer < ApplicationMailer ) end - def notify_followers_of_post_update(comment:) - @tenant = comment.tenant - Current.tenant = @tenant + def notify_follower_of_post_update(comment:, follower:) + Current.tenant = comment.tenant @comment = comment + @user = follower mail( - to: comment.post.followers.pluck(:email), - subject: t('mailers.user.notify_followers_of_post_update.subject', site_name: site_name, post: comment.post.title) + to: follower.email, + subject: t('mailers.user.notify_follower_of_post_update.subject', site_name: site_name, post: comment.post.title) ) end - def notify_followers_of_post_status_change(post:) - @tenant = post.tenant - Current.tenant = @tenant + def notify_follower_of_post_status_change(post:, follower:) + Current.tenant = post.tenant @post = post + @user = follower mail( - to: post.followers.pluck(:email), - subject: t('mailers.user.notify_followers_of_post_status_change.subject', site_name: site_name, post: post.title) + to: follower.email, + subject: t('mailers.user.notify_follower_of_post_status_change.subject', site_name: site_name, post: post.title) ) end diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb index 65b2888b..daab879c 100644 --- a/app/views/layouts/mailer.html.erb +++ b/app/views/layouts/mailer.html.erb @@ -4,6 +4,13 @@
-