feat: Include archived chats on user page
This commit is contained in:
parent
5a9ecce1cf
commit
feeb67f68e
5 changed files with 32 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
defmodule BdfrBrowser.Chat do
|
defmodule BdfrBrowser.Chat do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
import Ecto.Query, only: [from: 2]
|
import Ecto.Query, only: [from: 2, where: 3]
|
||||||
|
|
||||||
alias BdfrBrowser.Message
|
alias BdfrBrowser.Message
|
||||||
|
|
||||||
|
@ -21,4 +21,8 @@ defmodule BdfrBrowser.Chat do
|
||||||
group_by: c.id
|
group_by: c.id
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def by_author(author) do
|
||||||
|
listing() |> where([c], ^author in c.accounts)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -92,7 +92,8 @@ defmodule BdfrBrowser.HTTP.Plug do
|
||||||
tpl_args = [
|
tpl_args = [
|
||||||
name: name,
|
name: name,
|
||||||
posts: name |> Post.by_author() |> Repo.all(),
|
posts: name |> Post.by_author() |> Repo.all(),
|
||||||
comments: name |> Comment.by_author() |> Repo.all()
|
comments: name |> Comment.by_author() |> Repo.all(),
|
||||||
|
chats: name |> Chat.by_author() |> Repo.all()
|
||||||
]
|
]
|
||||||
|
|
||||||
content = render_template("user", tpl_args)
|
content = render_template("user", tpl_args)
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<footer class="blockquote-footer">
|
<footer class="blockquote-footer">
|
||||||
<a href="/user/<%= comment.author %>"><%= comment.author %></a>
|
<a href="/user/<%= comment.author %>"><%= comment.author %></a>,
|
||||||
<small><%= DateTime.to_iso8601(comment.posted_at) %></small>
|
<small><%= DateTime.to_iso8601(comment.posted_at) %></small>
|
||||||
</footer>
|
</footer>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<%= BdfrBrowser.RenderUtils.message(message.message) %>
|
<%= BdfrBrowser.RenderUtils.message(message.message) %>
|
||||||
|
|
||||||
<footer class="blockquote-footer">
|
<footer class="blockquote-footer">
|
||||||
<%= message.author %>,
|
<a href="/user/<%= message.author %>"><%= message.author %></a>,
|
||||||
<small><%= DateTime.to_iso8601(message.posted_at) %></small>
|
<small><%= DateTime.to_iso8601(message.posted_at) %></small>
|
||||||
</footer>
|
</footer>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
|
@ -12,6 +12,12 @@
|
||||||
Comments (<%= length(comments) %>)
|
Comments (<%= length(comments) %>)
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li class="nav-item" role="presentation">
|
||||||
|
<button class="nav-link" id="chats-tab" data-bs-toggle="tab" data-bs-target="#chats" type="button" role="tab" aria-controls="chats" aria-selected="false">
|
||||||
|
Chats (<%= length(chats) %>)
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
|
@ -55,4 +61,21 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-pane" id="chats" role="tabpanel" aria-labelledby="chats-tab" tabindex="2">
|
||||||
|
<div class="row text-center" style="margin-top: 5px;">
|
||||||
|
<div class="d-grid gap-2 col-12 mx-auto">
|
||||||
|
<%= for chat <- chats do %>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title"><a href="/chats/<%= URI.encode(chat.id, &URI.char_unreserved?/1) %>"><%= Enum.join(chat.accounts, ", ") %></a></h5>
|
||||||
|
<h6 class="card-subtitle mb-2 text-body-secondary">
|
||||||
|
<%= chat.num_messages %> message(s) - <%= DateTime.to_iso8601(chat.latest_message) %>
|
||||||
|
</h6>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue