blob: c77ebced1c560df3bac134191a3726f0f10c3d4f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
class MessagesController < ApplicationController
before_filter :login_required
renders_in_global_context
def index
@messages = current_user.top_level_messages.paginate(:page => params[:page])
@root = Breadcrumb::ReceivedMessages.new
respond_to do |wants|
wants.html
wants.xml {render :xml => @messages}
end
end
def sent
@messages = current_user.sent_messages.paginate(:all,
:page => params[:page])
@root = Breadcrumb::SentMessages.new
end
def read
@message = current_user.received_messages.find(params[:id])
@message.read!
respond_to do |wants|
wants.js
end
end
def show
@message = Message.find(params[:id])
unless @message.sender == current_user or @message.recipient == current_user
raise ActiveRecord::RecordNotFound and return
end
@message.read if @message.recipient == current_user
respond_to do |wants|
wants.html
wants.xml {render :xml => @message}
wants.js {render :partial => "message", :layout => false}
end
end
def create
thread_options = params[:message].merge({:recipients => params[:message][:recipients], :sender => current_user})
@messages = MessageThread.new(thread_options)
if @messages.save
flash[:notice] = "#{@messages.title} sent"
redirect_to :action => :index
else
@message = @messages.message
render :action => :new
end
end
def new
@message = Message.new
end
# POST /messages/<id>/reply
def reply
original_message = current_user.received_messages.find(params[:id])
@message = original_message.build_reply(params[:message])
original_message.read! unless original_message.read?
if @message.save
flash[:notice] = "Your reply was sent"
redirect_to :action => :show, :id => original_message
else
flash[:error] = "Your message could not be sent"
redirect_to :action => :index
end
end
def auto_complete_for_message_recipients
login = params[:message][:recipients]
@users = User.find(:all,
:conditions => [ 'LOWER(login) LIKE ?', '%' + login.downcase + '%' ],
:limit => 10).reject{|u|u == current_user}
render :layout => false
end
end
|