Merge pull request #2842 from techAPJ/patch-2
FEATURE: show topic category in email subject
This commit is contained in:
commit
aeba5ca7d9
|
@ -84,18 +84,21 @@ class UserNotifications < ActionMailer::Base
|
|||
def user_replied(user, opts)
|
||||
opts[:allow_reply_by_email] = true
|
||||
opts[:use_site_subject] = true
|
||||
opts[:show_category_in_subject] = true
|
||||
notification_email(user, opts)
|
||||
end
|
||||
|
||||
def user_quoted(user, opts)
|
||||
opts[:allow_reply_by_email] = true
|
||||
opts[:use_site_subject] = true
|
||||
opts[:show_category_in_subject] = true
|
||||
notification_email(user, opts)
|
||||
end
|
||||
|
||||
def user_mentioned(user, opts)
|
||||
opts[:allow_reply_by_email] = true
|
||||
opts[:use_site_subject] = true
|
||||
opts[:show_category_in_subject] = true
|
||||
notification_email(user, opts)
|
||||
end
|
||||
|
||||
|
@ -103,6 +106,7 @@ class UserNotifications < ActionMailer::Base
|
|||
opts[:allow_reply_by_email] = true
|
||||
opts[:use_site_subject] = true
|
||||
opts[:add_re_to_subject] = true
|
||||
opts[:show_category_in_subject] = true
|
||||
notification_email(user, opts)
|
||||
end
|
||||
|
||||
|
@ -110,6 +114,7 @@ class UserNotifications < ActionMailer::Base
|
|||
opts[:allow_reply_by_email] = true
|
||||
opts[:use_site_subject] = true
|
||||
opts[:add_re_to_subject] = true
|
||||
opts[:show_category_in_subject] = false
|
||||
|
||||
# We use the 'user_posted' event when you are emailed a post in a PM.
|
||||
opts[:notification_type] = 'posted'
|
||||
|
@ -125,6 +130,7 @@ class UserNotifications < ActionMailer::Base
|
|||
allow_reply_by_email: true,
|
||||
use_site_subject: true,
|
||||
add_re_to_subject: true,
|
||||
show_category_in_subject: true,
|
||||
notification_type: "posted",
|
||||
user: user
|
||||
)
|
||||
|
@ -174,6 +180,7 @@ class UserNotifications < ActionMailer::Base
|
|||
allow_reply_by_email = opts[:allow_reply_by_email] unless user.suspended?
|
||||
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]
|
||||
|
||||
send_notification_email(
|
||||
title: title,
|
||||
|
@ -182,6 +189,7 @@ class UserNotifications < ActionMailer::Base
|
|||
allow_reply_by_email: allow_reply_by_email,
|
||||
use_site_subject: use_site_subject,
|
||||
add_re_to_subject: add_re_to_subject,
|
||||
show_category_in_subject: show_category_in_subject,
|
||||
notification_type: notification_type,
|
||||
user: user
|
||||
)
|
||||
|
@ -198,6 +206,19 @@ class UserNotifications < ActionMailer::Base
|
|||
notification_type = opts[:notification_type]
|
||||
user = opts[:user]
|
||||
|
||||
# category name
|
||||
category = Topic.find_by(id: post.topic_id).category
|
||||
if opts[:show_category_in_subject] && post.topic_id && !category.uncategorized?
|
||||
show_category_in_subject = category.name
|
||||
|
||||
# subcategory case
|
||||
if !category.parent_category_id.nil?
|
||||
show_category_in_subject = "#{Category.find_by(id: category.parent_category_id).name}/#{show_category_in_subject}"
|
||||
end
|
||||
else
|
||||
show_category_in_subject = nil
|
||||
end
|
||||
|
||||
context = ""
|
||||
tu = TopicUser.get(post.topic_id, user)
|
||||
context_posts = self.class.get_context_posts(post, tu)
|
||||
|
@ -241,6 +262,7 @@ class UserNotifications < ActionMailer::Base
|
|||
allow_reply_by_email: allow_reply_by_email,
|
||||
use_site_subject: use_site_subject,
|
||||
add_re_to_subject: add_re_to_subject,
|
||||
show_category_in_subject: show_category_in_subject,
|
||||
private_reply: post.topic.private_message?,
|
||||
include_respond_instructions: !user.suspended?,
|
||||
template: template,
|
||||
|
|
|
@ -395,7 +395,7 @@ email:
|
|||
default: 7
|
||||
enum: 'DigestEmailSiteSetting'
|
||||
email_custom_headers: 'Auto-Submitted: auto-generated'
|
||||
email_subject: '%{optional_re}[%{site_name}] %{optional_pm}%{topic_title}'
|
||||
email_subject: '%{optional_re}[%{site_name}] %{optional_pm}%{optional_cat}%{topic_title}'
|
||||
reply_by_email_enabled: false
|
||||
reply_by_email_address: ''
|
||||
pop3_polling_enabled: false
|
||||
|
|
|
@ -45,6 +45,7 @@ module Email
|
|||
subject.gsub!("%{site_name}", @template_args[:site_name])
|
||||
subject.gsub!("%{optional_re}", @opts[:add_re_to_subject] ? I18n.t('subject_re', template_args) : '')
|
||||
subject.gsub!("%{optional_pm}", @opts[:private_reply] ? I18n.t('subject_pm', template_args) : '')
|
||||
subject.gsub!("%{optional_cat}", @template_args[:show_category_in_subject] ? "[#{@template_args[:show_category_in_subject]}] " : '')
|
||||
subject.gsub!("%{topic_title}", @template_args[:topic_title]) if @template_args[:topic_title] # must be last for safety
|
||||
else
|
||||
subject = @opts[:subject]
|
||||
|
|
|
@ -71,15 +71,19 @@ describe UserNotifications do
|
|||
end
|
||||
|
||||
describe '.user_replied' do
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:category) { Fabricate(:category, name: 'India') }
|
||||
let(:topic) { Fabricate(:topic, category: category) }
|
||||
let(:post) { Fabricate(:post, topic: topic) }
|
||||
let(:response) { Fabricate(:post, topic: post.topic)}
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:notification) { Fabricate(:notification, user: user) }
|
||||
|
||||
|
||||
it 'generates a correct email' do
|
||||
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)
|
||||
|
||||
# subject should include category name
|
||||
expect(mail.subject).to match(/India/)
|
||||
|
||||
# 2 respond to links cause we have 1 context post
|
||||
mail.html_part.to_s.scan(/To respond/).count.should == 2
|
||||
|
||||
|
@ -113,6 +117,9 @@ describe UserNotifications do
|
|||
it 'generates a correct email' do
|
||||
mail = UserNotifications.user_posted(response.user, post: response, notification: notification)
|
||||
|
||||
# subject should not include category name
|
||||
expect(mail.subject).not_to match(/Uncategorized/)
|
||||
|
||||
# subject should include "Re:"
|
||||
expect(mail.subject).to match("Re:")
|
||||
|
||||
|
@ -262,13 +269,6 @@ describe UserNotifications do
|
|||
end
|
||||
end
|
||||
|
||||
describe "user posted" do
|
||||
include_examples "notification email building" do
|
||||
let(:notification_type) { :posted }
|
||||
include_examples "supports reply by email"
|
||||
end
|
||||
end
|
||||
|
||||
describe "user invited to a private message" do
|
||||
include_examples "notification email building" do
|
||||
let(:notification_type) { :invited_to_private_message }
|
||||
|
|
Loading…
Reference in New Issue