Feature: Include participants at the bottom of PM emails (#5797)

* Feature: Include participants at the bottom of PM emails

... as undecorated links.

https://meta.discourse.org/t/email-notification-recipients-unclear-when-pm-is-sent-to-multiple-users/26934/13?u=featheredtoast

Fix: missing translation for PM mentions

* display membership count as `group (count)`
This commit is contained in:
Jeff Wong 2018-05-03 15:50:06 -07:00 committed by GitHub
parent eca7017a2b
commit 62a8904729
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 0 deletions

View File

@ -444,6 +444,20 @@ class UserNotifications < ActionMailer::Base
else
I18n.t('subject_pm')
end
participants = "#{I18n.t("user_notifications.pm_participants")} "
participant_list = []
post.topic.allowed_groups.each do |group|
participant_list.push "[#{group.name} (#{group.users.count})](#{Discourse.base_url}/groups/#{group.name})"
end
post.topic.allowed_users.each do |user|
if SiteSetting.prioritize_username_in_ux?
participant_list.push "[#{user.username}](#{Discourse.base_url}/u/#{user.username_lower})"
else
participant_list.push "[#{user.name.blank? ? user.username : user.name}](#{Discourse.base_url}/u/#{user.username_lower})"
end
end
participants += participant_list.join(", ")
end
if SiteSetting.private_email?
@ -548,6 +562,7 @@ class UserNotifications < ActionMailer::Base
show_category_in_subject: show_category_in_subject,
private_reply: post.topic.private_message?,
subject_pm: subject_pm,
participants: participants,
include_respond_instructions: !(user.suspended? || user.staged?),
template: template,
site_description: SiteSetting.site_description,

View File

@ -31,6 +31,11 @@
<% end %>
<div class='footer'>%{respond_instructions}</div>
<% if post.topic.private_message? %>
<div class='undecorated-link-footer footer'>
%{participants}
</div>
<% end %>
<div class='footer'>%{unsubscribe_instructions}</div>
</div>

View File

@ -2614,6 +2614,8 @@ en:
posted_by: "Posted by %{username} on %{post_date}"
pm_participants: "Participants:"
invited_group_to_private_message_body: |
%{username} invited @%{group_name} to a message
@ -2747,6 +2749,18 @@ en:
%{respond_instructions}
user_mentioned_pm:
title: "User Mentioned PM"
subject_template: "[%{email_prefix}] [PM] %{topic_title}"
text_body_template: |
%{header_instructions}
%{message}
%{context}
%{respond_instructions}
user_group_mentioned:
title: "User Group Mentioned"
subject_template: "[%{email_prefix}] %{topic_title}"

View File

@ -96,6 +96,13 @@ module Email
html_override.gsub!("%{respond_instructions}", "")
end
if @template_args[:participants].present?
participants = PrettyText.cook(@template_args[:participants], sanitize: false).html_safe
html_override.gsub!("%{participants}", participants)
else
html_override.gsub!("%{participants}", "")
end
styled = Email::Styles.new(html_override, @opts)
styled.format_basic
if style = @opts[:style]
@ -112,6 +119,12 @@ module Email
body = @opts[:body]
body = I18n.t("#{@opts[:template]}.text_body_template", template_args).dup if @opts[:template]
if @template_args[:participants].present?
body << "\n"
body << @template_args[:participants]
body << "\n"
end
if @template_args[:unsubscribe_instructions].present?
body << "\n"
body << @template_args[:unsubscribe_instructions]

View File

@ -97,6 +97,7 @@ module Email
style('.lightbox-wrapper .meta', 'display: none')
correct_first_body_margin
correct_footer_style
style('div.undecorated-link-footer a', "font-weight: normal;")
reset_tables
onebox_styles
plugin_styles

View File

@ -247,6 +247,17 @@ describe Email::MessageBuilder do
end
context "PM multiple participants" do
let(:pm_multiple) { Email::MessageBuilder.new(to_address,
body: 'hello world',
private_reply: true,
participants: "user1, user2") }
it "lists participants out" do
expect(pm_multiple.body).to match('hello world\nuser1, user2')
end
end
context "from field" do
it "has the default from" do

View File

@ -423,6 +423,29 @@ describe UserNotifications do
expect(mail.subject).to include("[PM] ")
end
it "includes a list of participants, groups first with member lists" do
group1 = Fabricate(:group)
group2 = Fabricate(:group)
group1.name = "group1"
group2.name = "group2"
user1 = Fabricate(:user)
user2 = Fabricate(:user)
user1.username = "one"
user2.username = "two"
user1.groups = [ group1, group2 ]
user2.groups = [ group1 ]
topic.allowed_users = [ user1, user2 ]
topic.allowed_groups = [ group1, group2 ]
mail = UserNotifications.user_private_message(
response.user,
post: response,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash
)
expect(mail.body).to include("#{I18n.t("user_notifications.pm_participants")} [group1 (2)](http://test.localhost/groups/group1), [group2 (1)](http://test.localhost/groups/group2), [one](http://test.localhost/u/one), [two](http://test.localhost/u/two)")
end
context "when SiteSetting.group_name_in_subject is true" do
before do
SiteSetting.group_in_subject = true