@@ -3,6 +3,12 @@ class ConversationsController < ApplicationController
before_action :set_conversation, only: [:show]
before_action :check_permission, only: [:show]
+ def index
+ @conversations = current_user.conversations.sort_by{
+ |c| c.messages.last.created_at
+ }
+ end
+
def show
end
@@ -0,0 +1,15 @@
+<tr>
+ <td>
+ <%= link_to conversation.name, conversation %>
+ </td>
+ <% conversation.users.each do |user| %>
+ <%= link_to user_url(user), data_toggle: "tooltip", title: user.name do %>
+ <%= image_tag user.picture.tiny.url %>
+ <% end %>
+ <b><%= conversation.messages.last.user.name %>:</b> <%= truncate(conversation.messages.last.content) %>
+</tr>
@@ -0,0 +1,20 @@
+<% provide(:title, "Conversations") %>
+<h1>Conversations</h1>
+<table width="100%" class="table table-striped table-bordered table-hover">
+ <thead>
+ <tr>
+ <th>
+ Conversation
+ </th>
+ Participants
+ Last message
+ </tr>
+ </thead>
+ <tbody>
+ <%= render @conversations %>
+ </tbody>
+</table>
@@ -45,6 +45,9 @@
<li>
<%= link_to fa_icon("home fw", text: "Home"), home_path %>
</li>
+ <li>
+ <%= link_to fa_icon("envelope fw", text: "Conversations"), conversations_path %>
+ </li>
</ul>
</div>
@@ -11,4 +11,12 @@ class ConversationsControllerTest < ActionDispatch::IntegrationTest
get conversation_path conversations(:two)
assert_redirected_to root_path
+ test "last message should be shown in index" do
+ message = @user.messages.build(content: "Hello, world!",
+ conversation: conversations(:one))
+ message.save
+ get conversations_path
+ assert_match message.content, response.body