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 @@ -
<%= yield %>
+
+ + <%= image_tag('logo.png', alt: 'Astuto Logo', size: 64) %> + +
+
+ <%= yield %> +
diff --git a/app/views/layouts/user_mailer.html.erb b/app/views/layouts/user_mailer.html.erb deleted file mode 100644 index 5bd1a135..00000000 --- a/app/views/layouts/user_mailer.html.erb +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - -

<%= t('mailers.user.opening_greeting') %>

- -
<%= yield %>
- -

<%= t('mailers.user.closing_greeting') %>

- - - - diff --git a/app/views/layouts/user_mailer.text.erb b/app/views/layouts/user_mailer.text.erb deleted file mode 100644 index 37f0bddb..00000000 --- a/app/views/layouts/user_mailer.text.erb +++ /dev/null @@ -1 +0,0 @@ -<%= yield %> diff --git a/app/views/user_mailer/_closing.html.erb b/app/views/user_mailer/_closing.html.erb new file mode 100644 index 00000000..2a98aea2 --- /dev/null +++ b/app/views/user_mailer/_closing.html.erb @@ -0,0 +1 @@ +

<%= t('mailers.user.closing_greeting') %>

\ No newline at end of file diff --git a/app/views/user_mailer/_opening.html.erb b/app/views/user_mailer/_opening.html.erb new file mode 100644 index 00000000..3bf7c012 --- /dev/null +++ b/app/views/user_mailer/_opening.html.erb @@ -0,0 +1 @@ +

<%= t('mailers.user.opening_greeting', name: user_name) %>

\ No newline at end of file diff --git a/app/views/user_mailer/_quoted_text.html.erb b/app/views/user_mailer/_quoted_text.html.erb new file mode 100644 index 00000000..ccf6c2c4 --- /dev/null +++ b/app/views/user_mailer/_quoted_text.html.erb @@ -0,0 +1,3 @@ +

+ <%= text %> +

\ No newline at end of file diff --git a/app/views/user_mailer/_unsubscribe_from_post.html.erb b/app/views/user_mailer/_unsubscribe_from_post.html.erb new file mode 100644 index 00000000..5a52cf94 --- /dev/null +++ b/app/views/user_mailer/_unsubscribe_from_post.html.erb @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/app/views/user_mailer/_unsubscribe_from_site.html.erb b/app/views/user_mailer/_unsubscribe_from_site.html.erb new file mode 100644 index 00000000..50d25504 --- /dev/null +++ b/app/views/user_mailer/_unsubscribe_from_site.html.erb @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/app/views/user_mailer/notify_comment_owner.html.erb b/app/views/user_mailer/notify_comment_owner.html.erb index aeab0fc2..5e391ac3 100644 --- a/app/views/user_mailer/notify_comment_owner.html.erb +++ b/app/views/user_mailer/notify_comment_owner.html.erb @@ -1,11 +1,15 @@ -

- <%= t('mailers.user.notify_comment_owner.body', user: @comment.user.full_name, post: @comment.post.title) %> -

+<%= render 'user_mailer/opening', user_name: @user.full_name %>

- <%= @comment.body %> + <%= t('mailers.user.notify_comment_owner.body_html', user: @comment.user.full_name, post: @comment.post.title) %>:

+<%= render 'user_mailer/quoted_text', text: @comment.body %> +

<%= link_to t('mailers.user.learn_more'), add_subdomain_to(method(:post_url), @comment.post) %>

+ +<%= render 'user_mailer/closing' %> + +<%= render 'user_mailer/unsubscribe_from_site' %> \ No newline at end of file diff --git a/app/views/user_mailer/notify_follower_of_post_status_change.html.erb b/app/views/user_mailer/notify_follower_of_post_status_change.html.erb new file mode 100644 index 00000000..1b109144 --- /dev/null +++ b/app/views/user_mailer/notify_follower_of_post_status_change.html.erb @@ -0,0 +1,17 @@ +<%= render 'user_mailer/opening', user_name: @user.full_name %> + +

+ <%= t('mailers.user.notify_follower_of_post_status_change.body_html', post: @post.title) %>: +

+ +

+ <%= @post.post_status.name.upcase %> +

+ +

+ <%= link_to t('mailers.user.learn_more'), add_subdomain_to(method(:post_url), @post) %> +

+ +<%= render 'user_mailer/closing' %> + +<%= render 'user_mailer/unsubscribe_from_post', post: @post %> \ No newline at end of file diff --git a/app/views/user_mailer/notify_follower_of_post_update.html.erb b/app/views/user_mailer/notify_follower_of_post_update.html.erb new file mode 100644 index 00000000..30027911 --- /dev/null +++ b/app/views/user_mailer/notify_follower_of_post_update.html.erb @@ -0,0 +1,15 @@ +<%= render 'user_mailer/opening', user_name: @user.full_name %> + +

+ <%= t('mailers.user.notify_follower_of_post_update.body_html', user: @comment.user.full_name, post: @comment.post.title) %>: +

+ +<%= render 'user_mailer/quoted_text', text: @comment.body %> + +

+ <%= link_to t('mailers.user.learn_more'), add_subdomain_to(method(:post_url), @comment.post) %> +

+ +<%= render 'user_mailer/closing' %> + +<%= render 'user_mailer/unsubscribe_from_post', post: @comment.post %> \ No newline at end of file diff --git a/app/views/user_mailer/notify_followers_of_post_status_change.html.erb b/app/views/user_mailer/notify_followers_of_post_status_change.html.erb deleted file mode 100644 index 8cce3d17..00000000 --- a/app/views/user_mailer/notify_followers_of_post_status_change.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -

- <%= t('mailers.user.notify_followers_of_post_status_change.body', post: @post.title) %> - - <%= @post.post_status.name.upcase %> - -

- -

- <%= link_to t('mailers.user.learn_more'), add_subdomain_to(method(:post_url), @post) %> -

diff --git a/app/views/user_mailer/notify_followers_of_post_update.html.erb b/app/views/user_mailer/notify_followers_of_post_update.html.erb deleted file mode 100644 index ae883870..00000000 --- a/app/views/user_mailer/notify_followers_of_post_update.html.erb +++ /dev/null @@ -1,11 +0,0 @@ -

- <%= t('mailers.user.notify_followers_of_post_update.body', user: @comment.user.full_name, post: @comment.post.title) %> -

- -

- <%= @comment.body %> -

- -

- <%= link_to t('mailers.user.learn_more'), add_subdomain_to(method(:post_url), @comment.post) %> -

diff --git a/app/views/user_mailer/notify_post_owner.html.erb b/app/views/user_mailer/notify_post_owner.html.erb index 03f26b26..a2481d53 100644 --- a/app/views/user_mailer/notify_post_owner.html.erb +++ b/app/views/user_mailer/notify_post_owner.html.erb @@ -1,11 +1,15 @@ -

- <%= t('mailers.user.notify_post_owner.body', user: @comment.user.full_name, post: @comment.post.title) %> -

+<%= render 'user_mailer/opening', user_name: @user.full_name %>

- <%= @comment.body %> + <%= t('mailers.user.notify_post_owner.body_html', user: @comment.user.full_name, post: @comment.post.title) %>:

+<%= render 'user_mailer/quoted_text', text: @comment.body %> +

<%= link_to t('mailers.user.learn_more'), add_subdomain_to(method(:post_url), @comment.post) %>

+ +<%= render 'user_mailer/closing' %> + +<%= render 'user_mailer/unsubscribe_from_post', post: @comment.post %> \ No newline at end of file diff --git a/app/workflows/send_notification_for_comment_workflow.rb b/app/workflows/send_notification_for_comment_workflow.rb index b74b114d..c81a0b59 100644 --- a/app/workflows/send_notification_for_comment_workflow.rb +++ b/app/workflows/send_notification_for_comment_workflow.rb @@ -7,7 +7,9 @@ class SendNotificationForCommentWorkflow def run if comment.is_post_update # Post update - UserMailer.notify_followers_of_post_update(comment: comment).deliver_later + comment.post.followers.each do |follower| + UserMailer.notify_follower_of_post_update(comment: comment, follower: follower).deliver_later + end return end diff --git a/config/application.rb b/config/application.rb index 927f9a54..251236f5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -16,6 +16,9 @@ module App # -- all .rb files in that directory are automatically loaded after loading # the framework and any gems in your application. + # For assets in mailers + config.asset_host = ENV["BASE_URL"] + def base_url ENV["BASE_URL"] end diff --git a/config/environments/development.rb b/config/environments/development.rb index 635a62d4..b9a94f4a 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -10,6 +10,9 @@ Rails.application.configure do # For Devise config.action_mailer.default_url_options = { host: Rails.application.base_url } + # For ActionMailer previews + config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews" + # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. diff --git a/config/locales/backend/backend.de.yml b/config/locales/backend/backend.de.yml index b3e23f6d..2eb9ed80 100644 --- a/config/locales/backend/backend.de.yml +++ b/config/locales/backend/backend.de.yml @@ -40,10 +40,10 @@ de: notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' body: 'There is a status update on the post you are following "%{post}"' activerecord: diff --git a/config/locales/backend/backend.en.yml b/config/locales/backend/backend.en.yml index 1b86a8f6..aaf68fed 100644 --- a/config/locales/backend/backend.en.yml +++ b/config/locales/backend/backend.en.yml @@ -30,22 +30,24 @@ en: body3: "Your password won't change until you access the link above and create a new one." action: 'Change my password' user: - opening_greeting: 'Hello!' + opening_greeting: 'Hello %{name}!' closing_greeting: 'Have a great day!' learn_more: 'Click here to learn more' - unsubscribe: 'Annoyed? You can turn off notifications here' + unsubscribe_from_post_html: 'Annoyed? You can turn off notifications for this post %{href}' + unsubscribe_from_site_html: 'Annoyed? You can turn off all notifications %{href}' + unsubscribe_link: 'here' notify_post_owner: subject: '[%{site_name}] New comment on "%{post}"' - body: 'There is a new comment by "%{user}" on your post "%{post}"' + body_html: 'There is a new comment by %{user} on your post %{post}' notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' - body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + body_html: 'There is a new reply by %{user} to your comment on post %{post}' + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' - body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + body_html: 'There is a new update on the post you are following %{post}' + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' - body: 'There is a status update on the post you are following "%{post}"' + body_html: 'There is a status update on the post you are following %{post}' activerecord: models: board: diff --git a/config/locales/backend/backend.es.yml b/config/locales/backend/backend.es.yml index aab2dec4..20f5f5f5 100644 --- a/config/locales/backend/backend.es.yml +++ b/config/locales/backend/backend.es.yml @@ -40,10 +40,10 @@ es: notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' body: 'There is a status update on the post you are following "%{post}"' activerecord: diff --git a/config/locales/backend/backend.fr.yml b/config/locales/backend/backend.fr.yml index 6446544e..137233a7 100644 --- a/config/locales/backend/backend.fr.yml +++ b/config/locales/backend/backend.fr.yml @@ -40,10 +40,10 @@ fr: notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' body: 'There is a status update on the post you are following "%{post}"' activerecord: diff --git a/config/locales/backend/backend.it.yml b/config/locales/backend/backend.it.yml index 62b6e2c1..c56cc0be 100644 --- a/config/locales/backend/backend.it.yml +++ b/config/locales/backend/backend.it.yml @@ -40,10 +40,10 @@ it: notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' body: 'There is a status update on the post you are following "%{post}"' activerecord: diff --git a/config/locales/backend/backend.ja.yml b/config/locales/backend/backend.ja.yml index 4c7a7bd3..d4092dc8 100644 --- a/config/locales/backend/backend.ja.yml +++ b/config/locales/backend/backend.ja.yml @@ -40,10 +40,10 @@ ja: notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' body: 'There is a status update on the post you are following "%{post}"' activerecord: diff --git a/config/locales/backend/backend.ko.yml b/config/locales/backend/backend.ko.yml index cdf1f806..00897588 100644 --- a/config/locales/backend/backend.ko.yml +++ b/config/locales/backend/backend.ko.yml @@ -40,10 +40,10 @@ ko: notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' body: 'There is a status update on the post you are following "%{post}"' activerecord: diff --git a/config/locales/backend/backend.nl.yml b/config/locales/backend/backend.nl.yml index b17779d5..81961f55 100644 --- a/config/locales/backend/backend.nl.yml +++ b/config/locales/backend/backend.nl.yml @@ -40,10 +40,10 @@ nl: notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' body: 'There is a status update on the post you are following "%{post}"' activerecord: diff --git a/config/locales/backend/backend.pt.yml b/config/locales/backend/backend.pt.yml index 20319afd..c3e6363d 100644 --- a/config/locales/backend/backend.pt.yml +++ b/config/locales/backend/backend.pt.yml @@ -40,10 +40,10 @@ pt: notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' body: 'There is a status update on the post you are following "%{post}"' activerecord: diff --git a/config/locales/backend/backend.ru.yml b/config/locales/backend/backend.ru.yml index 4d4f34f6..ebca3d28 100644 --- a/config/locales/backend/backend.ru.yml +++ b/config/locales/backend/backend.ru.yml @@ -40,10 +40,10 @@ ru: notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' body: 'There is a status update on the post you are following "%{post}"' activerecord: diff --git a/config/locales/backend/backend.vi.yml b/config/locales/backend/backend.vi.yml index 486c98a0..498fb382 100644 --- a/config/locales/backend/backend.vi.yml +++ b/config/locales/backend/backend.vi.yml @@ -40,10 +40,10 @@ vi: notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' body: 'There is a status update on the post you are following "%{post}"' activerecord: diff --git a/config/locales/backend/backend.zh.yml b/config/locales/backend/backend.zh.yml index 9b926221..0ada3572 100644 --- a/config/locales/backend/backend.zh.yml +++ b/config/locales/backend/backend.zh.yml @@ -40,10 +40,10 @@ zh-CN: notify_comment_owner: subject: '[%{site_name}] New reply on your comment on post "%{post}"' body: 'There is a new reply by "%{user}" on your comment from post "%{post}"' - notify_followers_of_post_update: + notify_follower_of_post_update: subject: '[%{site_name}] New update for post "%{post}"' body: 'There is a new update on the post you are following "%{post}"' - notify_followers_of_post_status_change: + notify_follower_of_post_status_change: subject: '[%{site_name}] Status change on post "%{post}"' body: 'There is a status update on the post you are following "%{post}"' activerecord: diff --git a/spec/mailers/previews/user_mailer_preview.rb b/spec/mailers/previews/user_mailer_preview.rb index 3148bfc9..df596664 100644 --- a/spec/mailers/previews/user_mailer_preview.rb +++ b/spec/mailers/previews/user_mailer_preview.rb @@ -1,6 +1,36 @@ # Preview all emails at http://localhost:3000/rails/mailers/user_mailer + class UserMailerPreview < ActionMailer::Preview + def initialize(params={}) + super(params) + + Current.tenant = Tenant.first + end + def notify_post_owner UserMailer.notify_post_owner(comment: Comment.first) end + + def notify_comment_owner + comment = Comment.where.not(parent_id: nil).first || throw("No comment replies available") + UserMailer.notify_comment_owner(comment: comment) + end + + def notify_follower_of_post_update + comment = Comment.first + if comment.post.follows.empty? + throw("No followers available") + end + follower = comment.post.follows.first.user + UserMailer.notify_follower_of_post_update(comment: comment, follower: follower) + end + + def notify_follower_of_post_status_change + comment = Comment.first + if comment.post.follows.empty? + throw("No followers available") + end + follower = comment.post.follows.first.user + UserMailer.notify_follower_of_post_status_change(post: Post.first, follower: follower) + end end