Showing all messages in inbox, but sorting by date DESC and highlighting new ones. Adding link from message reading page back to inbox. Mark as read/unread.
This commit is contained in:
parent
44051f30d8
commit
3c79240a6a
5 changed files with 25 additions and 23 deletions
|
@ -32,6 +32,8 @@ class MessageController < ApplicationController
|
|||
if params[:message_id]
|
||||
id = params[:message_id]
|
||||
@message = Message.find_by_id(id)
|
||||
@message.message_read = 1
|
||||
@message.save
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,9 +49,16 @@ class MessageController < ApplicationController
|
|||
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
|
||||
|
|
|
@ -3,8 +3,8 @@ class User < ActiveRecord::Base
|
|||
|
||||
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"
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
<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>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<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>
|
||||
|
@ -12,19 +12,9 @@
|
|||
<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 %>
|
|
@ -24,6 +24,7 @@
|
|||
<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>
|
||||
|
|
Loading…
Add table
Reference in a new issue