1 class MessageController < ApplicationController
4 before_filter :authorize_web
5 before_filter :require_user
8 @title = 'send message'
10 to_user = User.find(params[:user_id])
11 body = params[:message][:body]
12 title = params[:message][:title]
16 message.to_user_id = params[:user_id]
17 message.from_user_id = @user.id
18 message.sent_on = Time.now
21 flash[:notice] = 'Message sent'
22 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
24 @message.errors.add("Sending message failed")
31 @title = 'read message'
32 @message = Message.find(params[:message_id], :conditions => ["to_user_id = ?", @user.id])
33 @message.message_read = 1
35 rescue ActiveRecord::RecordNotFound
36 render :nothing => true, :status => :not_found
41 if @user and params[:display_name] == @user.display_name
43 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
48 if params[:message_id]
49 id = params[:message_id]
50 message = Message.find_by_id(id)
51 if params[:mark] == 'unread'
58 message.message_read = message_read
60 flash[:notice] = "Message marked as #{mark_type}"
61 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name