From 98daafc24442a81c587ff529ad90f3648a2d381f Mon Sep 17 00:00:00 2001 From: Riccardo Graziosi <31478034+riggraz@users.noreply.github.com> Date: Sat, 9 Mar 2024 17:26:24 +0100 Subject: [PATCH] Improve emails (#305) --- app/controllers/posts_controller.rb | 4 ++- app/mailers/user_mailer.rb | 28 ++++++++--------- app/views/layouts/mailer.html.erb | 9 +++++- app/views/layouts/user_mailer.html.erb | 22 -------------- app/views/layouts/user_mailer.text.erb | 1 - app/views/user_mailer/_closing.html.erb | 1 + app/views/user_mailer/_opening.html.erb | 1 + app/views/user_mailer/_quoted_text.html.erb | 3 ++ .../_unsubscribe_from_post.html.erb | 11 +++++++ .../_unsubscribe_from_site.html.erb | 11 +++++++ .../user_mailer/notify_comment_owner.html.erb | 12 +++++--- ...fy_follower_of_post_status_change.html.erb | 17 +++++++++++ .../notify_follower_of_post_update.html.erb | 15 ++++++++++ ...y_followers_of_post_status_change.html.erb | 10 ------- .../notify_followers_of_post_update.html.erb | 11 ------- .../user_mailer/notify_post_owner.html.erb | 12 +++++--- .../send_notification_for_comment_workflow.rb | 4 ++- config/application.rb | 3 ++ config/environments/development.rb | 3 ++ config/locales/backend/backend.de.yml | 4 +-- config/locales/backend/backend.en.yml | 18 ++++++----- config/locales/backend/backend.es.yml | 4 +-- config/locales/backend/backend.fr.yml | 4 +-- config/locales/backend/backend.it.yml | 4 +-- config/locales/backend/backend.ja.yml | 4 +-- config/locales/backend/backend.ko.yml | 4 +-- config/locales/backend/backend.nl.yml | 4 +-- config/locales/backend/backend.pt.yml | 4 +-- config/locales/backend/backend.ru.yml | 4 +-- config/locales/backend/backend.vi.yml | 4 +-- config/locales/backend/backend.zh.yml | 4 +-- spec/mailers/previews/user_mailer_preview.rb | 30 +++++++++++++++++++ 32 files changed, 169 insertions(+), 101 deletions(-) delete mode 100644 app/views/layouts/user_mailer.html.erb delete mode 100644 app/views/layouts/user_mailer.text.erb create mode 100644 app/views/user_mailer/_closing.html.erb create mode 100644 app/views/user_mailer/_opening.html.erb create mode 100644 app/views/user_mailer/_quoted_text.html.erb create mode 100644 app/views/user_mailer/_unsubscribe_from_post.html.erb create mode 100644 app/views/user_mailer/_unsubscribe_from_site.html.erb create mode 100644 app/views/user_mailer/notify_follower_of_post_status_change.html.erb create mode 100644 app/views/user_mailer/notify_follower_of_post_update.html.erb delete mode 100644 app/views/user_mailer/notify_followers_of_post_status_change.html.erb delete mode 100644 app/views/user_mailer/notify_followers_of_post_update.html.erb 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 @@
-