From 50c89e21dae40ffb05ba109e8c75dddfd84480a8 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 23 Mar 2021 19:29:22 +0100 Subject: [PATCH] Make sure default publish date doesn't override the current one Signed-off-by: Thomas Citharel --- lib/mobilizon/posts/post.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mobilizon/posts/post.ex b/lib/mobilizon/posts/post.ex index 3642fe45..adf95598 100644 --- a/lib/mobilizon/posts/post.ex +++ b/lib/mobilizon/posts/post.ex @@ -138,11 +138,12 @@ defmodule Mobilizon.Posts.Post do defp process_tag(tag), do: Tag.changeset(%Tag{}, tag) defp maybe_put_publish_date(%Changeset{} = changeset) do - publish_at = + default_publish_at = if get_field(changeset, :draft, true) == false, do: DateTime.utc_now() |> DateTime.truncate(:second), else: nil + publish_at = get_change(changeset, :publish_at, default_publish_at) put_change(changeset, :publish_at, publish_at) end