Description:
Prevented empty messages from being sent and fixed a typo
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r377:08f39063736a - - 1 file changed: 7 inserted, 6 deleted

@@ -10,76 +10,77
10
10
11 def list
11 def list
12 @user = User.find(session[:user_id])
12 @user = User.find(session[:user_id])
13 @messages = Message.find_all_sent_by_user(@user)
13 @messages = Message.find_all_sent_by_user(@user)
14 end
14 end
15
15
16 def console
16 def console
17 @user = User.find(session[:user_id])
17 @user = User.find(session[:user_id])
18 @messages = Message.find_all_system_unreplied_messages
18 @messages = Message.find_all_system_unreplied_messages
19 end
19 end
20
20
21 def show
21 def show
22 @message = Message.find(params[:id])
22 @message = Message.find(params[:id])
23 end
23 end
24
24
25 def list_all
25 def list_all
26 @user = User.find(session[:user_id])
26 @user = User.find(session[:user_id])
27 @messages = Message.where(receiver_id: nil).order(:created_at)
27 @messages = Message.where(receiver_id: nil).order(:created_at)
28 end
28 end
29
29
30 def create
30 def create
31 user = User.find(session[:user_id])
31 user = User.find(session[:user_id])
32 @message = Message.new(params[:message])
32 @message = Message.new(params[:message])
33 @message.sender = user
33 @message.sender = user
34 - if !@message.save
34 + if @message.body == '' or !@message.save
35 - render :action => 'list' and return
35 + flash[:notice] = 'An error occurred'
36 else
36 else
37 flash[:notice] = 'New message posted'
37 flash[:notice] = 'New message posted'
38 - redirect_to :action => 'list'
39 end
38 end
39 + redirect_to :action => 'list'
40 end
40 end
41
41
42 def reply
42 def reply
43 user = User.find(session[:user_id])
43 user = User.find(session[:user_id])
44 @message = Message.new(params[:r_message])
44 @message = Message.new(params[:r_message])
45 @message.sender = user
45 @message.sender = user
46 - if !@message.save
46 + if @message.body == '' or !@message.save
47 - render :action => 'show' and return
47 + flash[:notice] = 'An error occurred'
48 + redirect_to :action => 'show', :id => @message.replying_message_id
48 else
49 else
49 flash[:notice] = 'Message replied'
50 flash[:notice] = 'Message replied'
50 rep_msg = @message.replying_message
51 rep_msg = @message.replying_message
51 rep_msg.replied = true
52 rep_msg.replied = true
52 rep_msg.save
53 rep_msg.save
53 redirect_to :action => 'console'
54 redirect_to :action => 'console'
54 end
55 end
55 end
56 end
56
57
57 def hide
58 def hide
58 message = Message.find(params[:id])
59 message = Message.find(params[:id])
59 message.replied = true
60 message.replied = true
60 message.save
61 message.save
61 - flash[:notice] = 'Message hided (just marked replied)'
62 + flash[:notice] = 'Message hidden (just marked replied)'
62 redirect_to :action => 'console'
63 redirect_to :action => 'console'
63 end
64 end
64
65
65 protected
66 protected
66 def build_replying_message_hierarchy(user)
67 def build_replying_message_hierarchy(user)
67 @all_messages = {}
68 @all_messages = {}
68
69
69
70
70 # manually build replies hierarchy (to improve efficiency)
71 # manually build replies hierarchy (to improve efficiency)
71 [@messages, @replied_messages].each do |collection|
72 [@messages, @replied_messages].each do |collection|
72 collection.each do |m|
73 collection.each do |m|
73 @all_messages[m.id] = {:msg => m, :replies => []}
74 @all_messages[m.id] = {:msg => m, :replies => []}
74 end
75 end
75 end
76 end
76
77
77 @all_messages.each do |m|
78 @all_messages.each do |m|
78 rep_id = m.replying_message_id
79 rep_id = m.replying_message_id
79 if @all_messages[rep_id]!=nil
80 if @all_messages[rep_id]!=nil
80 @all_messages[rep_id][:replies] << m
81 @all_messages[rep_id][:replies] << m
81 end
82 end
82 end
83 end
83 end
84 end
84
85
85 end
86 end
You need to be logged in to leave comments. Login now