X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/ff03138a978406b431da71aba64941d87b509098..92951c6c00be0cb488a97463e25a5ecc8272c49e:/app/controllers/message_controller.rb diff --git a/app/controllers/message_controller.rb b/app/controllers/message_controller.rb index 2e5e09b45..73abc68cc 100644 --- a/app/controllers/message_controller.rb +++ b/app/controllers/message_controller.rb @@ -12,22 +12,32 @@ class MessageController < ApplicationController # clicks send. # The display_name param is the display name of the user that the message is being sent to. def new - @title = t 'message.new.title' @to_user = User.find_by_display_name(params[:display_name]) if @to_user if params[:message] - @message = Message.new(params[:message]) - @message.to_user_id = @to_user.id - @message.from_user_id = @user.id - @message.sent_on = Time.now.getutc + if @user.sent_messages.count(:conditions => ["sent_on >= ?", Time.now.getutc - 1.hour]) >= APP_CONFIG['max_messages_per_hour'] + flash[:error] = t 'message.new.limit_exceeded' + else + @message = Message.new(params[:message]) + @message.to_user_id = @to_user.id + @message.from_user_id = @user.id + @message.sent_on = Time.now.getutc - if @message.save - flash[:notice] = t 'message.new.message_sent' - Notifier::deliver_message_notification(@message) - redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name + if @message.save + flash[:notice] = t 'message.new.message_sent' + Notifier::deliver_message_notification(@message) + redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name + end end else - @title = params[:title] + if params[:title] + # ?title= is set when someone reponds to this user's diary + # entry. Then we pre-fill out the subject and the