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
24 @message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ])
25 if !@message.message_read
26 flash[:notice] = 'Message not read and so not deleted'
27 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
29 flash[:notice] = "Message '#{@message.title}' deleted"
31 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
36 message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ])
37 title = message.title.sub(/^Re:\s*/, "Re: ")
38 redirect_to :action => 'new', :user_id => message.from_user_id, :title => title
39 rescue ActiveRecord::RecordNotFound
40 render :nothing => true, :status => :not_found
44 @title = 'read message'
45 @message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ])
46 @message.message_read = 1 if @message.to_user_id == @user.id
48 rescue ActiveRecord::RecordNotFound
49 render :nothing => true, :status => :not_found
54 if @user and params[:display_name] == @user.display_name
56 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
62 if @user and params[:display_name] == @user.display_name
64 redirect_to :controller => 'message', :action => 'outbox', :display_name => @user.display_name
69 if params[:message_id]
70 id = params[:message_id]
71 message = Message.find_by_id(id)
72 if params[:mark] == 'unread'
79 message.message_read = message_read
81 flash[:notice] = "Message marked as #{mark_type}"
82 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name