From 92ce228cbe24ed030090823d2a4e92ee5089732c Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 14 Oct 2012 11:56:00 +0100 Subject: [PATCH] Get note comment notification working again --- app/controllers/notes_controller.rb | 4 ++-- app/models/notifier.rb | 24 +++++++++---------- .../note_comment_notification.html.erb | 12 ++++------ .../note_comment_notification.text.erb | 13 ++++++++++ config/locales/en.yml | 4 ++-- 5 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 app/views/notifier/note_comment_notification.text.erb diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index fe3615d7a..95659a771 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -319,11 +319,11 @@ private attributes[:author_name] = name + " (a)" end - note.comments.create(attributes, :without_protection => true) + comment = note.comments.create(attributes, :without_protection => true) note.comments.map { |c| c.author }.uniq.each do |user| if user and user != @user - Notifier.deliver_note_comment_notification(comment, user) + Notifier.note_comment_notification(comment, user).deliver end end end diff --git a/app/models/notifier.rb b/app/models/notifier.rb index 2fb00c96f..5ec401d18 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -115,19 +115,17 @@ class Notifier < ActionMailer::Base end def note_comment_notification(comment, recipient) - common_headers recipient - owner = (recipient == comment.note.author); - subject I18n.t('notifier.note_plain.subject_own', :commenter => comment.author_name) if owner - subject I18n.t('notifier.note_plain.subject_other', :commenter => comment.author_name) unless owner - - body :nodeurl => url_for(:host => SERVER_URL, - :controller => "browse", - :action => "note", - :id => comment.note_id), - :place => comment.note.nearby_place, - :comment => comment.body, - :owner => owner, - :commenter => comment.author_name + @locale = recipient.preferred_language_from(I18n.available_locales) + @noteurl = browse_note_url(comment.note, :host => SERVER_URL) + @place = comment.note.nearby_place + @comment = RichText::Text.new(comment.body) + @owner = recipient == comment.note.author + @commenter = comment.author_name + + subject = I18n.t('notifier.note_comment_notification.subject_own', :commenter => comment.author_name) if @owner + subject = I18n.t('notifier.note_comment_notification.subject_other', :commenter => comment.author_name) unless @owner + + mail :to => recipient.email, :subject => subject end private diff --git a/app/views/notifier/note_comment_notification.html.erb b/app/views/notifier/note_comment_notification.html.erb index fade148d8..b17fe67f8 100644 --- a/app/views/notifier/note_comment_notification.html.erb +++ b/app/views/notifier/note_comment_notification.html.erb @@ -1,15 +1,13 @@ -<%= t 'notifier.note_plain.greeting' %> +

<%= t 'notifier.note_comment_notification.greeting' %>

<% if @owner %> -<%= t 'notifier.note_plain.your_note', :commenter => @commenter, :place => @place %> +

<%= t 'notifier.note_comment_notification.your_note', :commenter => @commenter, :place => @place %>

<% else %> -<%= t 'notifier.note_plain.commented_note', :commenter => @commenter, :place => @place %> +

<%= t 'notifier.note_comment_notification.commented_note', :commenter => @commenter, :place => @place %>

<% end %> == -<%= @comment %> +<%= @comment.to_html %> == -<%= t 'notifier.note_plain.details', :URL => @noteurl %> - - +

<%= raw t 'notifier.note_comment_notification.details', :url => link_to(@noteurl, @noteurl) %>

diff --git a/app/views/notifier/note_comment_notification.text.erb b/app/views/notifier/note_comment_notification.text.erb new file mode 100644 index 000000000..7b4ccd384 --- /dev/null +++ b/app/views/notifier/note_comment_notification.text.erb @@ -0,0 +1,13 @@ +<%= t 'notifier.note_comment_notification.greeting' %> + +<% if @owner %> +<%= t 'notifier.note_comment_notification.your_note', :commenter => @commenter, :place => @place %> +<% else %> +<%= t 'notifier.note_comment_notification.commented_note', :commenter => @commenter, :place => @place %> +<% end %> + +== +<%= @comment %> +== + +<%= t 'notifier.note_comment_notification.details', :url => @noteurl %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 09c43fc09..37d5c395a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1213,13 +1213,13 @@ en: greeting: "Hi," hopefully_you: "Someone (possibly you) has asked for the password to be reset on this email address's openstreetmap.org account." click_the_link: "If this is you, please click the link below to reset your password." - note_plain: + note_comment_notification: subject_own: "[OpenStreetMap] %{commenter} has commented on one of your notes" subject_other: "[OpenStreetMap] %{commenter} has commented on a note you are interested in" greeting: "Hi," your_note: "%{commenter} has left a comment on one of your map notes near %{place}." commented_note: "%{commenter} has left a comment on a map note you have commented on. The note is near %{place}." - details: "More details about the note can be found at %{URL}." + details: "More details about the note can be found at %{url}." message: inbox: title: "Inbox" -- 2.43.2