before_filter :authorize_web
before_filter :set_locale
before_filter :require_user
+ before_filter :lookup_this_user, :only => [:new]
before_filter :check_database_readable
before_filter :check_database_writable, :only => [:new, :reply, :mark]
# clicks send.
# The display_name param is the display name of the user that the message is being sent to.
def new
- @to_user = User.find_by_display_name(params[:display_name])
- if @to_user
- if params[:message]
- if @user.sent_messages.where("sent_on >= ?", Time.now.getutc - 1.hour).count >= 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.message_notification(@message).deliver
- redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
- end
- end
+ if params[:message]
+ if @user.sent_messages.where("sent_on >= ?", Time.now.getutc - 1.hour).count >= MAX_MESSAGES_PER_HOUR
+ flash[:error] = t 'message.new.limit_exceeded'
else
- if params[:title]
- # ?title= is set when someone reponds to this user's diary
- # entry. Then we pre-fill out the subject and the <title>
- @title = @subject = params[:title]
- else
- # The default /message/new/$user view
- @title = t 'message.new.title'
+ @message = Message.new(params[:message])
+ @message.to_user_id = @this_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.message_notification(@message).deliver
+ redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
end
end
else
- render_unknown_user params[:display_name]
+ if params[:title]
+ # ?title= is set when someone reponds to this user's diary
+ # entry. Then we pre-fill out the subject and the <title>
+ @title = @subject = params[:title]
+ else
+ # The default /message/new/$user view
+ @title = t 'message.new.title'
+ end
end
end