feat: Include archived chats on user page

This commit is contained in:
Daniel Kempkens 2023-08-15 17:36:04 +02:00
parent 5a9ecce1cf
commit feeb67f68e
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM
5 changed files with 32 additions and 4 deletions

View file

@ -1,7 +1,7 @@
defmodule BdfrBrowser.Chat do
use Ecto.Schema
import Ecto.Query, only: [from: 2]
import Ecto.Query, only: [from: 2, where: 3]
alias BdfrBrowser.Message
@ -21,4 +21,8 @@ defmodule BdfrBrowser.Chat do
group_by: c.id
)
end
def by_author(author) do
listing() |> where([c], ^author in c.accounts)
end
end

View file

@ -92,7 +92,8 @@ defmodule BdfrBrowser.HTTP.Plug do
tpl_args = [
name: name,
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)

View file

@ -9,7 +9,7 @@
<% end %>
<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>
</footer>
</blockquote>

View file

@ -8,7 +8,7 @@
<%= BdfrBrowser.RenderUtils.message(message.message) %>
<footer class="blockquote-footer">
<%= message.author %>,
<a href="/user/<%= message.author %>"><%= message.author %></a>,
<small><%= DateTime.to_iso8601(message.posted_at) %></small>
</footer>
</blockquote>

View file

@ -12,6 +12,12 @@
Comments (<%= length(comments) %>)
</button>
</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>
<div class="tab-content">
@ -55,4 +61,21 @@
</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>