From af989b9673c72e38c33d4a92ff44231d2847beba Mon Sep 17 00:00:00 2001 From: Vincent Degove Date: Tue, 5 Sep 2023 16:08:19 +0200 Subject: [PATCH] =?UTF-8?q?R=C3=A9pare=20discussions=20repli=C3=A9es=20(#3?= =?UTF-8?q?439)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * compare datetime to get the max one instead of relying on order * more elixirish syntax * use pattern matching * mix credo --- .../lib/transport_web/live/discussions_live.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/transport/lib/transport_web/live/discussions_live.ex b/apps/transport/lib/transport_web/live/discussions_live.ex index afb11995f2..1df879b86b 100644 --- a/apps/transport/lib/transport_web/live/discussions_live.ex +++ b/apps/transport/lib/transport_web/live/discussions_live.ex @@ -89,8 +89,16 @@ defmodule TransportWeb.DiscussionsLive do def discussion_should_be_closed?(%{"closed" => closed}) when not is_nil(closed), do: true def discussion_should_be_closed?(%{"discussion" => comment_list}) do - {:ok, latest_comment_datetime, 0} = List.first(comment_list)["posted_on"] |> DateTime.from_iso8601() - DateTime.utc_now() |> Timex.shift(months: -2) |> DateTime.compare(latest_comment_datetime) == :gt + latest_comment_datetime = + comment_list + |> Enum.map(fn comment -> + {:ok, comment_datetime, 0} = DateTime.from_iso8601(comment["posted_on"]) + comment_datetime + end) + |> Enum.max(DateTime) + + two_months_ago = DateTime.utc_now() |> Timex.shift(months: -2) + DateTime.compare(two_months_ago, latest_comment_datetime) == :gt end end