From d5db44da87290d3ee34a733cfa33e0e9b3dc9f46 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Tue, 7 Apr 2015 11:51:38 +0530 Subject: [PATCH] FIX: include topic excerpt in topic/message invite mail for existing user --- app/mailers/user_notifications.rb | 36 ++++++++++++++++++++----------- config/locales/server.en.yml | 26 ++++++++++++++++++---- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index a977ba653f5..74295249e73 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -79,10 +79,6 @@ class UserNotifications < ActionMailer::Base end end - def user_invited_to_private_message(user, opts) - notification_email(user, opts) - end - def user_replied(user, opts) opts[:allow_reply_by_email] = true opts[:use_site_subject] = true @@ -124,7 +120,13 @@ class UserNotifications < ActionMailer::Base notification_email(user, opts) end + def user_invited_to_private_message(user, opts) + opts[:use_template_html] = true + notification_email(user, opts) + end + def user_invited_to_topic(user, opts) + opts[:use_template_html] = true opts[:show_category_in_subject] = true notification_email(user, opts) end @@ -193,6 +195,7 @@ class UserNotifications < ActionMailer::Base use_site_subject = opts[:use_site_subject] add_re_to_subject = opts[:add_re_to_subject] show_category_in_subject = opts[:show_category_in_subject] + use_template_html = opts[:use_template_html] original_username = @notification.data_hash[:original_username] || @notification.data_hash[:display_username] send_notification_email( @@ -205,6 +208,7 @@ class UserNotifications < ActionMailer::Base add_re_to_subject: add_re_to_subject, show_category_in_subject: show_category_in_subject, notification_type: notification_type, + use_template_html: use_template_html, user: user ) @@ -248,20 +252,26 @@ class UserNotifications < ActionMailer::Base end end - html = UserNotificationRenderer.new(Rails.configuration.paths["app/views"]).render( - template: 'email/notification', - format: :html, - locals: { context_posts: context_posts, - post: post, - classes: RTL.new(user).css_class - } - ) + topic_excerpt = "" + if opts[:use_template_html] + topic_excerpt = post.excerpt.gsub("\n", " ") if post.is_first_post? && post.excerpt + else + html = UserNotificationRenderer.new(Rails.configuration.paths["app/views"]).render( + template: 'email/notification', + format: :html, + locals: { context_posts: context_posts, + post: post, + classes: RTL.new(user).css_class + } + ) + end template = "user_notifications.user_#{notification_type}" template << "_pm" if post.topic.private_message? email_opts = { topic_title: title, + topic_excerpt: topic_excerpt, message: email_post_markdown(post), url: post.url, post_id: post.id, @@ -277,6 +287,8 @@ class UserNotifications < ActionMailer::Base include_respond_instructions: !user.suspended?, template: template, html_override: html, + site_description: SiteSetting.site_description, + site_title: SiteSetting.title, style: :notification } diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index c7abd8d7137..97f0e6b6c4d 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1771,16 +1771,34 @@ en: user_invited_to_private_message_pm: subject_template: "[%{site_name}] %{username} invited you to a message '%{topic_title}'" text_body_template: | - %{username} invited you to a message '%{topic_title}' on %{site_name}: - Please visit this link to view the topic: %{base_url}%{url} + %{username} invited you to a message + + > **%{topic_title}** + > + > %{topic_excerpt} + + at + + > %{site_title} -- %{site_description} + + Please visit this link to view the message: %{base_url}%{url} user_invited_to_topic: subject_template: "[%{site_name}] %{username} invited you to a topic '%{topic_title}'" text_body_template: | - %{username} invited you to a topic '%{topic_title}' on %{site_name}: - Please visit this link to view the topic: %{base_url}%{url} + %{username} invited you to a discussion + + > **%{topic_title}** + > + > %{topic_excerpt} + + at + + > %{site_title} -- %{site_description} + + Please visit this link to view the message: %{base_url}%{url} user_replied: subject_template: "[%{site_name}] %{topic_title}"