New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dressed up notification mails #1401
Changes from 12 commits
e6d1958
45e90cf
689769c
1f0f7ba
94062a1
5f663b7
b5ef2be
20bd72d
1d86379
b5fd9f5
20a74fc
7a4e13e
ab9aaf7
beaa85e
ac08130
479a4bd
417176f
3aa69ff
31778fd
0449024
e59d6c5
39c3fa4
22f7c1f
6d1c10a
235e77f
7ef57b2
75f96fc
c942138
433b7c5
a0627ec
1e19e80
e5152c3
e3e5ad4
1285c9f
774e583
25d8078
cf11913
1def88b
f83b719
a371aad
74e28f8
223a12c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,10 +154,12 @@ def note_comment_notification(comment, recipient) | |
|
||
def changeset_comment_notification(comment, recipient) | ||
with_recipient_locale recipient do | ||
@root_url = root_url(:host => SERVER_URL) | ||
@changeset_url = changeset_url(comment.changeset, :host => SERVER_URL) | ||
@comment = comment.body | ||
@owner = recipient == comment.changeset.user | ||
@commenter = comment.author.display_name | ||
@commenter_url = user_url(comment.author.display_name, :host => SERVER_URL) | ||
@changeset_comment = comment.changeset.tags["comment"].presence | ||
@time = comment.created_at | ||
@changeset_author = comment.changeset.user.display_name | ||
|
@@ -168,12 +170,24 @@ def changeset_comment_notification(comment, recipient) | |
I18n.t("notifier.changeset_comment_notification.commented.subject_other", :commenter => @commenter) | ||
end | ||
|
||
attachments.inline["logo.png"] = File.read(Rails.root.join("app", "assets", "images", "osm_logo_30.png")) | ||
attachments.inline["avatar.png"] = File.read(user_avatar_file_path(comment.author)) | ||
|
||
mail :to => recipient.email, :subject => subject | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_avatar_file_path(user) | ||
image = user.image | ||
if image.file? | ||
return image.path.sub("/original/", "/small/") | ||
else | ||
return Rails.root.join("app", "assets", "images", "users", "images", "small.png") | ||
end | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't got time to look it up right now, but this all looks horribly wrong to me. I'm sure the first branch of the if must have a better solution than that if you read up on paperclip and the second ought to be done with ...so having now looked it up There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
However Would you find the above code less objectionable if I just concatenated it all into one string using slashes, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well in production you can just concat that with Rails.public_path and it should read fine though I'll grant you that might not work in development... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect your single string version is probably the best option. It shouldn't matter that we're avoiding the asset pipeline give it's all happening server side... |
||
def with_recipient_locale(recipient) | ||
I18n.with_locale Locale.available.preferred(recipient.preferred_languages) do | ||
yield | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,73 @@ | ||
<p><%= t 'notifier.changeset_comment_notification.greeting' %></p> | ||
|
||
<p> | ||
<% if @owner %> | ||
<%= t "notifier.changeset_comment_notification.commented.your_changeset", :commenter => @commenter, :time => @time %> | ||
<% else %> | ||
<%= t "notifier.changeset_comment_notification.commented.commented_changeset", :commenter => @commenter, :time => @time, :changeset_author => @changeset_author %> | ||
<% end %> | ||
<% if @changeset_comment %> | ||
<%= t "notifier.changeset_comment_notification.commented.partial_changeset_with_comment", :changeset_comment => @changeset_comment %> | ||
<% else %> | ||
<%= t "notifier.changeset_comment_notification.commented.partial_changeset_without_comment" %> | ||
<% end %> | ||
</p> | ||
|
||
== | ||
<%= @comment.to_html %> | ||
== | ||
|
||
<p><%= raw t 'notifier.changeset_comment_notification.details', :url => link_to(@changeset_url, @changeset_url) %></p> | ||
<html> | ||
<head> | ||
<title></title> | ||
<meta charset="UTF-8"></meta> | ||
</head> | ||
<body style="padding: 0; margin: 0; font-size: 14px; font-family: 'Helvetica Neue', Arial, sans-serif; color: #222"> | ||
<table style="background-color: #eee; width: 100%"> | ||
<tr> | ||
<td style="text-align: center"> | ||
<table style="width: 600px; color: #222; margin-left: auto; margin-right: auto"> | ||
<tr> | ||
<td style="width: 30px; padding: 10px"> | ||
<a href="<%= @root_url %>" target="_blank"> | ||
<%= image_tag attachments["logo.png"].url, alt: "OpenStreetMap logo", title: "OpenStreetMap", height: "30", width: "30", border: "0" %> | ||
</a> | ||
</td> | ||
<td style="padding: 10px 0px"> | ||
<a href="<%= @root_url %>" target="_blank" style="text-decoration: none; color: #000"> | ||
<h1 style="font-size: 18px; font-weight: 600; margin: 0; text-align: left">OpenStreetMap</h1> | ||
</a> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td colspan="2"> | ||
<table style="background-color: #fff; color: #222; border: solid 1px #ccc; border-collapse: separate"> | ||
<tr> | ||
<td style="text-align: left; padding: 15px 15px 5px 15px"> | ||
<p style="margin: 0"> | ||
<% if @owner %> | ||
<%= t "notifier.changeset_comment_notification.commented.your_changeset_html", :commenter => @commenter, :commenter_url => @commenter_url, :time => @time %> | ||
<% else %> | ||
<%= t "notifier.changeset_comment_notification.commented.commented_changeset_html", :commenter => @commenter, :commenter_url => @commenter_url, :time => @time, :changeset_author => @changeset_author %> | ||
<% end %> | ||
<% if @changeset_comment %> | ||
<%= t "notifier.changeset_comment_notification.commented.partial_changeset_with_comment_html", :changeset_comment => @changeset_comment %> | ||
<% else %> | ||
<%= t "notifier.changeset_comment_notification.commented.partial_changeset_without_comment" %> | ||
<% end %> | ||
</p> | ||
<table style="font-size: 15px; font-style: italic; margin: 15px; background-color: #eee; width: 520px"> | ||
<tr> | ||
<td style="width: 50px; vertical-align: top; padding: 15px"> | ||
<a href="<%= @commenter_url %>" target="_blank"><%= image_tag attachments["avatar.png"].url, alt: @commenter %></a> | ||
</td> | ||
<td style="text-align: left; vertical-align: top; padding-right: 10px"> | ||
<%= @comment.to_html %> | ||
</td> | ||
</tr> | ||
</table> | ||
<p> | ||
<%= raw t 'notifier.changeset_comment_notification.details_html', :url => link_to(@changeset_url, @changeset_url) %> | ||
</p> | ||
</td> | ||
</tr> | ||
</table> | ||
</td> | ||
</tr> | ||
</table> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td style="text-align: center; font-size: 11px"> | ||
<p> | ||
<%= t 'notifier.changeset_comment_notification.unsubscribe_html', :url => @changeset_url %> | ||
</p> | ||
<p style="margin-bottom: 10px"> | ||
<a href="<%= @root_url %>" target="_blank" style="color: #222">OpenStreetMap</a> | ||
</p> | ||
</td> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of boiler plate here that makes this very hard to read, and if you're planning to expand this to other emails then I then think you need to look for a way to separate it out so that it's not duplicated all over the shop. Is there something clever we can do here with a layout? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1315,10 +1315,23 @@ en: | |
subject_own: "[OpenStreetMap] %{commenter} has commented on one of your changesets" | ||
subject_other: "[OpenStreetMap] %{commenter} has commented on a changeset you are interested in" | ||
your_changeset: "%{commenter} has left a comment on one of your changesets created at %{time}" | ||
your_changeset_html: '<a href="%{commenter_url}" target="_blank" style="text-decoration: none; color: #222"><strong>%{commenter}</strong></a> | ||
has left a comment on one of your changesets | ||
created at %{time}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a translation nightmare - aside from the fact that it duplicates the plain text version there's all sorts of stuff here that is technical detail that we don't really want to expose translators to if we can avoid it as they'll just manage to break it. Do we really need the strong tag? Without that we can just reuse the text version and put the HTML in the template. If we do want it can't we add it as part of the commenter expansion and achieve the same result? Obviously the same applies to other translations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've now moved the HTML markup to the template. The *_html duplicated strings are no longer necessary and have been removed. |
||
commented_changeset: "%{commenter} has left a comment on a map changeset you are watching created by %{changeset_author} at %{time}" | ||
commented_changeset_html: '<a href="%{commenter_url}" target="_blank" style="text-decoration: none; color: #222"><strong>%{commenter}</strong></a> | ||
has left a comment on a map changeset you are watching created by | ||
%{changeset_author} | ||
at %{time}' | ||
partial_changeset_with_comment: "with comment '%{changeset_comment}'" | ||
partial_changeset_with_comment_html: 'with comment <em>%{changeset_comment}</em>' | ||
partial_changeset_without_comment: "without comment" | ||
details: "More details about the changeset can be found at %{url}." | ||
details_html: 'More details about the changeset can be found at | ||
<nobr>%{url}</nobr>.' | ||
unsubscribe_html: 'To unsubscribe from updates to this changeset, | ||
visit <nobr><a style="color: #222" href="%{url}">%{url}</a></nobr> | ||
and click "Unsubscribe".' | ||
message: | ||
inbox: | ||
title: "Inbox" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't thin use
image_path
or something? Explicitly building a path to an asset like that seems wrong.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed it to
File.read("#{Rails.root}/app/assets/images/osm_logo_30.png")
, as discussed below.