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 @body = "\n\nOn #{message.sent_on} #{message.sender.display_name} wrote:\n #{message.body}"
38 @title = "Re: #{message.title}"
39 @user_id = message.from_user_id
40 render :action => 'new'
41 rescue ActiveRecord::RecordNotFound
42 render :nothing => true, :status => :not_found
46 @title = 'read message'
47 @message = Message.find(params[:message_id], :conditions => ["to_user_id = ? or from_user_id = ?", @user.id, @user.id ])
48 @message.message_read = 1 if @message.to_user_id == @user.id
50 rescue ActiveRecord::RecordNotFound
51 render :nothing => true, :status => :not_found
56 if @user and params[:display_name] == @user.display_name
58 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
64 if @user and params[:display_name] == @user.display_name
66 redirect_to :controller => 'message', :action => 'outbox', :display_name => @user.display_name
71 if params[:message_id]
72 id = params[:message_id]
73 message = Message.find_by_id(id)
74 if params[:mark] == 'unread'
81 message.message_read = message_read
83 flash[:notice] = "Message marked as #{mark_type}"
84 redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name