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 if !@message.message_read
28 flash[:notice] = 'Message not read and so not deleted'
29 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
31 flash[:notice] = "Message '#{@message.title}' deleted"
33 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
38 message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ])
39 @body = "On #{message.sent_on} #{message.sender.display_name} wrote:\n\n#{message.body.gsub(/^/, '> ')}"
40 @title = "Re: #{message.title.sub(/^Re:\s*/, '')}"
41 @user_id = message.from_user_id
42 render :action => 'new'
43 rescue ActiveRecord::RecordNotFound
44 render :nothing => true, :status => :not_found
48 @title = 'read message'
49 @message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ])
50 @message.message_read = 1 if @message.to_user_id == @user.id
52 rescue ActiveRecord::RecordNotFound
53 render :nothing => true, :status => :not_found
58 if @user and params[:display_name] == @user.display_name
60 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
66 if @user and params[:display_name] == @user.display_name
68 redirect_to :controller => 'message', :action => 'outbox', :display_name => @user.display_name
73 if params[:message_id]
74 id = params[:message_id]
75 message = Message.find_by_id(id)
76 if params[:mark] == 'unread'
83 message.message_read = message_read
85 flash[:notice] = "Message marked as #{mark_type}"
86 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name