From feeb67f68e709d0214a5f9d5b2b9ae73ec09ce74 Mon Sep 17 00:00:00 2001 From: Daniel Kempkens Date: Tue, 15 Aug 2023 17:36:04 +0200 Subject: [PATCH] feat: Include archived chats on user page --- lib/bdfr_browser/chat.ex | 6 +++++- lib/bdfr_browser/http/plug.ex | 3 ++- priv/templates/http/_comment.eex | 2 +- priv/templates/http/chat.eex | 2 +- priv/templates/http/user.eex | 23 +++++++++++++++++++++++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/bdfr_browser/chat.ex b/lib/bdfr_browser/chat.ex index e0f5c08..031c920 100644 --- a/lib/bdfr_browser/chat.ex +++ b/lib/bdfr_browser/chat.ex @@ -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 diff --git a/lib/bdfr_browser/http/plug.ex b/lib/bdfr_browser/http/plug.ex index 97136d5..3125aa1 100644 --- a/lib/bdfr_browser/http/plug.ex +++ b/lib/bdfr_browser/http/plug.ex @@ -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) diff --git a/priv/templates/http/_comment.eex b/priv/templates/http/_comment.eex index a1333ec..565b518 100644 --- a/priv/templates/http/_comment.eex +++ b/priv/templates/http/_comment.eex @@ -9,7 +9,7 @@ <% end %> diff --git a/priv/templates/http/chat.eex b/priv/templates/http/chat.eex index b560641..65ccd53 100644 --- a/priv/templates/http/chat.eex +++ b/priv/templates/http/chat.eex @@ -8,7 +8,7 @@ <%= BdfrBrowser.RenderUtils.message(message.message) %> diff --git a/priv/templates/http/user.eex b/priv/templates/http/user.eex index 30688d0..d4422ce 100644 --- a/priv/templates/http/user.eex +++ b/priv/templates/http/user.eex @@ -12,6 +12,12 @@ Comments (<%= length(comments) %>) + +
@@ -55,4 +61,21 @@
+ +
+
+
+ <%= for chat <- chats do %> +
+
+
<%= Enum.join(chat.accounts, ", ") %>
+
+ <%= chat.num_messages %> message(s) - <%= DateTime.to_iso8601(chat.latest_message) %> +
+
+
+ <% end %> +
+
+