FEATURE: keep original title when sending email notifications about a PM

This commit is contained in:
Régis Hanol 2016-02-23 01:34:16 +01:00
parent 6eb8730fce
commit 8d1da9cedd
4 changed files with 37 additions and 12 deletions

View File

@ -236,25 +236,20 @@ class UserNotifications < ActionMailer::Base
user_name = name unless name.blank? user_name = name unless name.blank?
end end
title = notification_data[:topic_title]
allow_reply_by_email = opts[:allow_reply_by_email] unless user.suspended? 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]
use_template_html = opts[:use_template_html]
original_username = notification_data[:original_username] || notification_data[:display_username] original_username = notification_data[:original_username] || notification_data[:display_username]
send_notification_email( send_notification_email(
title: title, title: notification_data[:topic_title],
post: post, post: post,
username: original_username, username: original_username,
from_alias: user_name, from_alias: user_name,
allow_reply_by_email: allow_reply_by_email, allow_reply_by_email: allow_reply_by_email,
use_site_subject: use_site_subject, use_site_subject: opts[:use_site_subject],
add_re_to_subject: add_re_to_subject, add_re_to_subject: opts[:add_re_to_subject],
show_category_in_subject: show_category_in_subject, show_category_in_subject: opts[:show_category_in_subject],
notification_type: notification_type, notification_type: notification_type,
use_template_html: use_template_html, use_template_html: opts[:use_template_html],
user: user user: user
) )
end end

View File

@ -98,8 +98,8 @@ class Notification < ActiveRecord::Base
# Be wary of calling this frequently. O(n) JSON parsing can suck. # Be wary of calling this frequently. O(n) JSON parsing can suck.
def data_hash def data_hash
@data_hash ||= begin @data_hash ||= begin
return nil if data.blank? return nil if data.blank?
parsed = JSON.parse(data) parsed = JSON.parse(data)
return nil if parsed.blank? return nil if parsed.blank?

View File

@ -259,8 +259,16 @@ class PostAlerter
UserActionObserver.log_notification(original_post, user, type, opts[:acting_user_id]) UserActionObserver.log_notification(original_post, user, type, opts[:acting_user_id])
topic_title = post.topic.title
# when sending a private message email, keep the original title
if post.topic.private_message? && modifications = post.revisions.map(&:modifications).to_a
if first_title_modification = modifications.first { |m| m.has_key?("title") }
topic_title = first_title_modification["title"][0]
end
end
notification_data = { notification_data = {
topic_title: post.topic.title, topic_title: topic_title,
original_post_id: original_post.id, original_post_id: original_post.id,
original_post_type: original_post.post_type, original_post_type: original_post.post_type,
original_username: original_username, original_username: original_username,

View File

@ -150,4 +150,26 @@ describe PostAlerter do
end end
end end
describe ".create_notification" do
it "keeps the original title for PMs" do
user = Fabricate(:user)
topic = Fabricate(:private_message_topic, user: user, created_at: 1.hour.ago)
post = Fabricate(:post, topic: topic, created_at: 1.hour.ago)
original_title = topic.title
post.revise(user, { title: "This is the revised title" }, revised_at: Time.now)
expect {
PostAlerter.new.create_notification(user, Notification.types[:private_message], post)
}.to change { user.notifications.count }
expect(user.notifications.last.data_hash["topic_title"]).to eq(original_title)
end
end
end end