if params[:message_id]
id = params[:message_id]
@message = Message.find_by_id(id)
+ @message.message_read = 1
+ @message.save
end
end
if params[:message_id]
id = params[:message_id]
message = Message.find_by_id(id)
- message.message_read = 1
+ if params[:mark] == 'unread'
+ message_read = 0
+ mark_type = 'unread'
+ else
+ message_read = 1
+ mark_type = 'read'
+ end
+ message.message_read = message_read
if message.save
- flash[:notice] = 'Message marked as read'
+ flash[:notice] = "Message marked as #{mark_type}"
redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
end
end
has_many :traces
has_many :diary_entries, :order => 'created_at DESC'
- has_many :messages, :foreign_key => :to_user_id
- has_many :new_messages, :class_name => "Message", :foreign_key => :to_user_id, :conditions => "message_read = 0"
+ has_many :messages, :foreign_key => :to_user_id, :order => 'sent_on DESC'
+ has_many :new_messages, :class_name => "Message", :foreign_key => :to_user_id, :conditions => "message_read = 0", :order => 'sent_on DESC'
has_many :friends
has_many :tokens, :class_name => "UserToken"
has_many :preferences, :class_name => "UserPreference"
<tr>
<td><%= link_to message_summary.sender.display_name , :controller => 'user', :action => message_summary.sender.display_name %></td>
- <td><%= link_to message_summary.title , :controller => 'message', :action => 'read', :message_id => message_summary.id %></td>
+ <td><%= "<b>" if not message_summary.message_read? %>
+ <%= link_to message_summary.title , :controller => 'message', :action => 'read', :message_id => message_summary.id %>
+ <%= "</b>" if not message_summary.message_read? %></td>
<td><%= message_summary.sent_on %></td>
<% if message_summary.message_read? %>
- <td>Message read</td>
+ <td><%= button_to 'Mark as unread', :controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'unread' %></td>
<% else %>
- <td><%= button_to 'Mark as read', :controller => 'message', :action => 'mark', :message_id => message_summary.id %> </td>
+ <td><%= button_to 'Mark as read', :controller => 'message', :action => 'mark', :message_id => message_summary.id, :mark => 'read' %></td>
<% end %>
- <td><%= button_to 'Reply', :controller => 'message', :action => 'new', :user_id => message_summary.from_user_id %> </td>
+ <td><%= button_to 'Reply', :controller => 'message', :action => 'new', :user_id => message_summary.from_user_id %></td>
</tr>
<p>You have <%= @user.new_messages.size %> new messages and <%= @user.messages.size - @user.new_messages.size %> old messages</p>
-<% if (params[:all] and @user.messages.size > 0) or (@user.new_messages.size > 0) %>
+<% if @user.messages.size > 0 %>
<div id="messages">
<table class="messages">
<tr>
<th></th>
<th></th>
</tr>
- <% if params[:all] %>
- <%= render :partial => "message_summary", :collection => @user.messages %>
- <% else %>
- <%= render :partial => "message_summary", :collection => @user.new_messages %>
- <% end %>
+ <%= render :partial => "message_summary", :collection => @user.messages %>
</table>
</div>
-<% end %>
-
-<br />
-
-<% if params[:all] %>
- <%= link_to 'Show new messages', :controller => 'message', :action => 'inbox', :display_name => @user.display_name %>
<% else %>
- <%= link_to 'Show all messages', :controller => 'message', :action => 'inbox', :display_name => @user.display_name, :all => true %>
-<% end %>
+ <div id="messages">You have no messages yet. Why not get in touch with some of the <%= link_to 'people mapping nearby', :controller => 'user', :action => 'view', :display_name => @user.display_name %>?</div>
+<% end %>
\ No newline at end of file
<table>
<tr>
<td><%= button_to 'Reply', :controller => 'message', :action => 'new', :user_id => @message.from_user_id %></td>
- <td><%= button_to 'Mark as read', :controller => 'message', :action => 'mark', :message_id => @message.id %></td>
+ <td><%= button_to 'Mark as unread', :controller => 'message', :action => 'mark', :message_id => @message.id, :mark => 'unread' %></td>
+ <td><%= link_to 'Back to inbox', :controller => 'message', :action => 'inbox', :display_name => @user.display_name %></td>
</tr>
</table>