Make sure default publish date doesn't override the current one

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-03-23 19:29:22 +01:00
parent b002d905cb
commit 50c89e21da
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
1 changed files with 2 additions and 1 deletions

View File

@ -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