]> git.openstreetmap.org Git - rails.git/commitdiff
Send email notifications when people comment on diary entries. Closes #655.
authorTom Hughes <tom@compton.nu>
Mon, 4 Feb 2008 00:15:28 +0000 (00:15 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 4 Feb 2008 00:15:28 +0000 (00:15 +0000)
app/controllers/diary_entry_controller.rb
app/models/notifier.rb
app/views/diary_entry/_diary_comment.rhtml
app/views/notifier/diary_comment_notification.rhtml [new file with mode: 0644]

index 13d3121a5eef32de418f4beada6a907df5570428..643728dc44a7408efb52944d03d4441947f0ec41 100644 (file)
@@ -20,6 +20,7 @@ class DiaryEntryController < ApplicationController
     @diary_comment = @entry.diary_comments.build(params[:diary_comment])
     @diary_comment.user = @user
     if @diary_comment.save
+      Notifier::deliver_diary_comment_notification(@diary_comment)
       redirect_to :controller => 'diary_entry', :action => 'view', :display_name => @entry.user.display_name, :id => @entry.id
     else
       render :action => 'view'
index f934a8bde42a6a95939fd81c7ea2495cb8018f42..f6870a8ad34d6654852fed1b38c5d1e99c361a00 100644 (file)
@@ -63,6 +63,34 @@ class Notifier < ActionMailer::Base
                               :message_id => message.id)
   end
 
+  def diary_comment_notification(comment)
+    recipients comment.diary_entry.user.email
+    from "webmaster@openstreetmap.org"
+    subject "[OpenStreetMap] #{comment.user.display_name} commented on your diary entry"
+    headers "Auto-Submitted" => "auto-generated"
+    body :to_user => comment.diary_entry.user.display_name,
+         :from_user => comment.user.display_name,
+         :body => comment.body,
+         :subject => comment.diary_entry.title,
+         :readurl => url_for(:host => SERVER_URL,
+                             :controller => "diary_entry",
+                             :action => "view",
+                             :display_name => comment.diary_entry.user.display_name,
+                             :id => comment.diary_entry.id,
+                             :anchor => "comment#{comment.id}"),
+         :commenturl => url_for(:host => SERVER_URL,
+                                :controller => "diary_entry",
+                                :action => "view",
+                                :display_name => comment.diary_entry.user.display_name,
+                                :id => comment.diary_entry.id,
+                                :anchor => "newcomment"),
+         :replyurl => url_for(:host => SERVER_URL,
+                              :controller => "message",
+                              :action => "new",
+                              :user_id => comment.user.id,
+                              :title => "Re: #{comment.diary_entry.title}")
+  end
+
   def friend_notification(friend)
     befriender = User.find_by_id(friend.user_id)
     befriendee = User.find_by_id(friend.friend_user_id)
index 2e7d0a53103392e7d907269d2ff2439405d48446..be621cf5b7d4b68f39077c276236e575f74f243b 100644 (file)
@@ -1,3 +1,3 @@
-<h4>Comment from <%= link_to diary_comment.user.display_name, :controller => 'user', :action => 'view', :display_name => diary_comment.user.display_name %>  at <%= diary_comment.created_at %></h4>
+<h4 id="comment<%= diary_comment.id %>">Comment from <%= link_to diary_comment.user.display_name, :controller => 'user', :action => 'view', :display_name => diary_comment.user.display_name %>  at <%= diary_comment.created_at %></h4>
 <%= htmlize(diary_comment.body) %>
 <hr />
diff --git a/app/views/notifier/diary_comment_notification.rhtml b/app/views/notifier/diary_comment_notification.rhtml
new file mode 100644 (file)
index 0000000..05b1f08
--- /dev/null
@@ -0,0 +1,20 @@
+***************************************************************************
+Please do not reply to this email. Use the OpenStreetMap web site to reply.
+***************************************************************************
+
+Hi <%= @to_user %>,
+
+<%= @from_user %> has commented on your recent OpenStreetMap diary entry
+with the subject "<%= @subject %>":
+
+==
+<%= @body %>
+==
+
+You can also read the comment at <%= @readurl %>
+and you can comment at <%= @commenturl %>
+or reply at <%= @replyurl %>
+
+***************************************************************************
+Please do not reply to this email. Use the OpenStreetMap web site to reply.
+***************************************************************************