summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornfoy <nfoy@purdue.edu>2014-04-26 23:45:18 -0400
committernfoy <nfoy@purdue.edu>2014-04-26 23:45:18 -0400
commit9d8d6b023ce3390f3ccf9808e630505a15ebebe6 (patch)
tree3e7d2e04b69f10cdcefd61372524da8181f8802d
parent2c1e5ab5e7b20dabec9ddb9b34e0cf534afc6d06 (diff)
Messages now check if they're read/unread except when creating a message.
-rw-r--r--app/views/pms/index.html.erb97
-rw-r--r--app/views/pms/show.html.erb8
2 files changed, 68 insertions, 37 deletions
diff --git a/app/views/pms/index.html.erb b/app/views/pms/index.html.erb
index a13705a..560cf38 100644
--- a/app/views/pms/index.html.erb
+++ b/app/views/pms/index.html.erb
@@ -1,4 +1,10 @@
-<h1>Conversations</h1>
+<h1> Your Conversations </h1>
+
+<%= link_to 'Start a new conversation', new_pm_path %>
+<br>
+
+<h3>Unread Conversations</h3>
+<% conversations = current_user.mailbox.conversations %>
<table>
<col width="150">
@@ -6,43 +12,68 @@
<col width="300">
<tbody>
<tr>
- <% conversations = current_user.mailbox.conversations %>
- <% if !conversations.empty? %>
- <%# require 'pp' %>
- <%= conversations.class %>
- <tr>
- <td><b>With</b></td>
- <td><b>Subject</b></td>
- <td><b>Body</b></td>
- </tr>
- <% conversations.each do |conversation| %>
- <% receipts = conversation.receipts_for current_user %>
- <%# receipts.each do |receipt| %>
- <% message = receipts.last.message %>
- <tr>
- <td>
- <% people = conversation.participants %>
- <% people.each do |person| %>
- <% unless person == current_user %>
- <%= truncate(person.user_name, length: 20) %>
- <% end %>
+ <tr>
+ <td><b>With</b></td>
+ <td><b>Subject</b></td>
+ <td><b>Body</b></td>
+ </tr>
+ <% conversations.each do |conversation| %>
+ <% receipts = conversation.receipts_for current_user %>
+ <% if conversation.is_unread?(current_user) && receipts.last.message.sender != current_user %>
+ <% message = receipts.last.message %>
+ <tr>
+ <td>
+ <% people = conversation.participants %>
+ <% people.each do |person| %>
+ <% unless person == current_user %>
+ <%= truncate(person.user_name, length: 20) %>
<% end %>
- </td>
- <td><%= truncate(conversation.subject, length: 30) %></td>
- <td><%= truncate(message.body, length: 42) %></td>
- <td><%= link_to 'View', @pms.find_by(conversation: conversation) %></td>
- </tr>
- <%# end %>
+ <% end %>
+ </td>
+ <td><%= truncate(conversation.subject, length: 30) %></td>
+ <td><%= truncate(message.body, length: 42) %></td>
+ <td><%= link_to 'View', @pms.find_by(conversation: conversation) %></td>
+ </tr>
<% end %>
-
- <% else %>
- <td><p> No Messages </p></td>
<% end %>
- </tr>
-
+ </tr>
</tbody>
</table>
<br>
+<h3>Read Conversations</h3>
+<% conversations = current_user.mailbox.conversations %>
-<%= link_to 'New Pm', new_pm_path %>
+<table>
+ <col width="150">
+ <col width="250">
+ <col width="300">
+ <tbody>
+ <tr>
+ <tr>
+ <td><b>With</b></td>
+ <td><b>Subject</b></td>
+ <td><b>Body</b></td>
+ </tr>
+ <% conversations.each do |conversation| %>
+ <% receipts = conversation.receipts_for current_user %>
+ <% if conversation.is_read?(current_user) || receipts.last.message.sender == current_user %>
+ <% message = receipts.last.message %>
+ <tr>
+ <td>
+ <% people = conversation.participants %>
+ <% people.each do |person| %>
+ <% unless person == current_user %>
+ <%= truncate(person.user_name, length: 20) %>
+ <% end %>
+ <% end %>
+ </td>
+ <td><%= truncate(conversation.subject, length: 30) %></td>
+ <td><%= truncate(message.body, length: 42) %></td>
+ <td><%= link_to 'View', @pms.find_by(conversation: conversation) %></td>
+ </tr>
+ <% end %>
+ <% end %>
+ </tr>
+ </tbody>
+</table> \ No newline at end of file
diff --git a/app/views/pms/show.html.erb b/app/views/pms/show.html.erb
index 64dd66e..ca8d9bf 100644
--- a/app/views/pms/show.html.erb
+++ b/app/views/pms/show.html.erb
@@ -4,10 +4,10 @@
<% receps.each do |recep| %>
<% #unless recep == @pm.conversation.last_sender %>
<%= recep.user_name %>
- <%= "and" %>
+ <%= "," %>
<% #end %>
<% end %>
- <%= "the NSA" %>
+ <%= "and the NSA" %>
</p>
<p>
@@ -22,7 +22,7 @@
<p> ________________________________________________ </p>
<p>
- <%= message.sender.user_name %>
+ <b><%= message.sender.user_name %></b>
<%= ":" %>
<%= message.body %>
</p>
@@ -43,5 +43,5 @@
<% end %>
</p>
-
+<% @pm.conversation.mark_as_read(current_user) %>
<%= link_to 'Back', pms_path %>