Send an email notification out when a new message is waiting on the site for you.
authorDan Karran <dan@karran.net>
Wed, 5 Sep 2007 22:27:22 +0000 (22:27 +0000)
committerDan Karran <dan@karran.net>
Wed, 5 Sep 2007 22:27:22 +0000 (22:27 +0000)
app/controllers/message_controller.rb
app/models/notifier.rb
app/views/notifier/message_notification.rhtml [new file with mode: 0644]

index 8521d76b3f5cf326604aac6b634e84ab1b411379..52f38e9f6a1d3d4e166423b432b57ea9b6b4a7d7 100644 (file)
@@ -14,6 +14,7 @@ class MessageController < ApplicationController
    
       if @message.save
         flash[:notice] = 'Message sent'
+        Notifier::deliver_message_notification(@message)
         redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
       end
     end
index aaad67d0ea68a95497ced34dc9111b7eac2baefb..00bec921c022d02f9b9e3cd6e54669266375b585 100644 (file)
@@ -37,4 +37,16 @@ class Notifier < ActionMailer::Base
     @body['trace_name'] = trace.name
     @body['error'] = error
   end
+  
+  def message_notification(message)
+    @from_user = User.find(message.from_user_id)
+    @to_user = User.find(message.to_user_id)
+    @recipients = @to_user.email
+    @from = 'abuse@openstreetmap.org'
+    @subject = "[OpenStreetMap] #{@from_user.display_name} sent you a new message"
+    @body['to_user'] = @to_user.display_name
+    @body['from_user'] = @from_user.display_name
+    @body['subject'] = message.title
+    @body['url'] = "http://#{SERVER_URL}/message/read/#{message.id}"
+  end
 end
diff --git a/app/views/notifier/message_notification.rhtml b/app/views/notifier/message_notification.rhtml
new file mode 100644 (file)
index 0000000..79a03d0
--- /dev/null
@@ -0,0 +1,5 @@
+Hi <%= @to_user %>,
+
+<%= @from_user %> has sent you a message through OpenStreetMap with the subject "<%= @subject %>". You can read the message at:
+
+<%= @url %>
\ No newline at end of file