Added mail notification when a new message is posted in the forums.
Only users who "watch" the board receive notifications. To watch a board, go to the board and click on the "Watch" link. Notifications are sent by MessageObserver observer. GLoc was modified to use the mail template without language suffix when translated template (with language suffix) doesn't exist. Usefull when there's no hard coded text in the mail tempate. git-svn-id: http://redmine.rubyforge.org/svn/trunk@531 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
bca5bd9c62
commit
7ca7e4bad5
|
@ -87,4 +87,12 @@ class Mailer < ActionMailer::Base
|
|||
@subject = l(:mail_subject_register)
|
||||
@body['token'] = token
|
||||
end
|
||||
|
||||
def message_posted(message, recipients)
|
||||
set_language_if_valid(Setting.default_language)
|
||||
@recipients = recipients
|
||||
@from = Setting.mail_from
|
||||
@subject = "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
|
||||
@body['message'] = message
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class MessageObserver < ActiveRecord::Observer
|
||||
def after_create(message)
|
||||
# send notification to board watchers
|
||||
recipients = message.board.watcher_recipients
|
||||
Mailer.deliver_message_posted(message, recipients) unless recipients.empty?
|
||||
end
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
<%= l(:field_author) %>: <%= @message.author.name %>
|
||||
<%= url_for :only_path => false, :host => Setting.host_name, :controller => 'messages', :action => 'show', :board_id => @message.board_id, :id => @message.root %>
|
||||
|
||||
<%= @message.content %>
|
|
@ -27,9 +27,10 @@ Rails::Initializer.run do |config|
|
|||
# Enable page/fragment caching by setting a file-based store
|
||||
# (remember to create the caching directory and make it readable to the application)
|
||||
# config.action_controller.fragment_cache_store = :file_store, "#{RAILS_ROOT}/cache"
|
||||
|
||||
|
||||
# Activate observers that should always be running
|
||||
# config.active_record.observers = :cacher, :garbage_collector
|
||||
config.active_record.observers = :message_observer
|
||||
|
||||
# Make Active Record use UTC-base instead of local time
|
||||
# config.active_record.default_timezone = :utc
|
||||
|
|
|
@ -92,7 +92,8 @@ module ActionMailer #:nodoc:
|
|||
private
|
||||
alias :render_message_without_gloc :render_message
|
||||
def render_message(method_name, body)
|
||||
render_message_without_gloc("#{method_name}_#{current_language}", body)
|
||||
template = File.exist?("#{template_path}/#{method_name}_#{current_language}.rhtml") ? "#{method_name}_#{current_language}" : "#{method_name}"
|
||||
render_message_without_gloc(template, body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue