##// END OF EJS Templates
Added mail notification when a new message is posted in the forums....
Jean-Philippe Lang -
r528:7ca7e4bad503
parent child
Show More
@@ -0,0 +1,24
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 class MessageObserver < ActiveRecord::Observer
19 def after_create(message)
20 # send notification to board watchers
21 recipients = message.board.watcher_recipients
22 Mailer.deliver_message_posted(message, recipients) unless recipients.empty?
23 end
24 end
@@ -0,0 +1,4
1 <%= l(:field_author) %>: <%= @message.author.name %>
2 <%= url_for :only_path => false, :host => Setting.host_name, :controller => 'messages', :action => 'show', :board_id => @message.board_id, :id => @message.root %>
3
4 <%= @message.content %>
@@ -87,4 +87,12 class Mailer < ActionMailer::Base
87 @subject = l(:mail_subject_register)
87 @subject = l(:mail_subject_register)
88 @body['token'] = token
88 @body['token'] = token
89 end
89 end
90
91 def message_posted(message, recipients)
92 set_language_if_valid(Setting.default_language)
93 @recipients = recipients
94 @from = Setting.mail_from
95 @subject = "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
96 @body['message'] = message
97 end
90 end
98 end
@@ -27,9 +27,10 Rails::Initializer.run do |config|
27 # Enable page/fragment caching by setting a file-based store
27 # Enable page/fragment caching by setting a file-based store
28 # (remember to create the caching directory and make it readable to the application)
28 # (remember to create the caching directory and make it readable to the application)
29 # config.action_controller.fragment_cache_store = :file_store, "#{RAILS_ROOT}/cache"
29 # config.action_controller.fragment_cache_store = :file_store, "#{RAILS_ROOT}/cache"
30
30
31 # Activate observers that should always be running
31 # Activate observers that should always be running
32 # config.active_record.observers = :cacher, :garbage_collector
32 # config.active_record.observers = :cacher, :garbage_collector
33 config.active_record.observers = :message_observer
33
34
34 # Make Active Record use UTC-base instead of local time
35 # Make Active Record use UTC-base instead of local time
35 # config.active_record.default_timezone = :utc
36 # config.active_record.default_timezone = :utc
@@ -92,7 +92,8 module ActionMailer #:nodoc:
92 private
92 private
93 alias :render_message_without_gloc :render_message
93 alias :render_message_without_gloc :render_message
94 def render_message(method_name, body)
94 def render_message(method_name, body)
95 render_message_without_gloc("#{method_name}_#{current_language}", body)
95 template = File.exist?("#{template_path}/#{method_name}_#{current_language}.rhtml") ? "#{method_name}_#{current_language}" : "#{method_name}"
96 render_message_without_gloc(template, body)
96 end
97 end
97 end
98 end
98 end
99 end
General Comments 0
You need to be logged in to leave comments. Login now