Limit the rate at which messages can be sent.
This commit is contained in:
parent
2d7fa37bd2
commit
81d47fe50d
3 changed files with 15 additions and 8 deletions
|
@ -15,15 +15,19 @@ class MessageController < ApplicationController
|
|||
@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[:notice] = 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
|
||||
if params[:title]
|
||||
|
|
|
@ -17,6 +17,8 @@ standard_settings: &standard_settings
|
|||
api_timeout: 300
|
||||
# Periods (in hours) which are allowed for user blocks
|
||||
user_block_periods: [0, 1, 3, 6, 12, 24, 48, 96]
|
||||
# Rate limit for message sending
|
||||
max_messages_per_hour: 60
|
||||
|
||||
development:
|
||||
<<: *standard_settings
|
||||
|
|
|
@ -581,6 +581,7 @@ en:
|
|||
send_button: "Send"
|
||||
back_to_inbox: "Back to inbox"
|
||||
message_sent: "Message sent"
|
||||
limit_exceeded: "You have sent a lot of messages recently, please wait a while before trying to send any more."
|
||||
no_such_user:
|
||||
title: "No such user or message"
|
||||
heading: "No such user or message"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue