1 class MessageController < ApplicationController
4 before_filter :authorize_web
5 before_filter :require_user
8 @title = 'send message'
10 @message = Message.new(params[:message])
11 @message.to_user_id = params[:user_id]
12 @message.from_user_id = @user.id
13 @message.sent_on = Time.now
16 flash[:notice] = 'Message sent'
17 Notifier::deliver_message_notification(@message)
18 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
21 @title = params[:title]
26 message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ])
27 @body = "On #{message.sent_on} #{message.sender.display_name} wrote:\n\n#{message.body.gsub(/^/, '> ')}"
28 @title = "Re: #{message.title.sub(/^Re:\s*/, '')}"
29 @user_id = message.from_user_id
30 render :action => 'new'
31 rescue ActiveRecord::RecordNotFound
32 render :nothing => true, :status => :not_found
36 @title = 'read message'
37 @message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ])
38 @message.message_read = 1 if @message.to_user_id == @user.id
40 rescue ActiveRecord::RecordNotFound
41 render :nothing => true, :status => :not_found
46 if @user and params[:display_name] == @user.display_name
48 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
54 if @user and params[:display_name] == @user.display_name
56 redirect_to :controller => 'message', :action => 'outbox', :display_name => @user.display_name
61 if params[:message_id]
62 id = params[:message_id]
63 message = Message.find_by_id(id)
64 if params[:mark] == 'unread'
71 message.message_read = message_read
73 flash[:notice] = "Message marked as #{mark_type}"
74 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name