Fix posts not able to accept existing tags

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-10-20 11:50:39 +02:00
parent 3ecc2cbad7
commit df22082f3e
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -22,8 +22,8 @@ defmodule Mobilizon.Posts.Post do
import Ecto.Changeset import Ecto.Changeset
alias Ecto.Changeset alias Ecto.Changeset
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.{Events, Medias}
alias Mobilizon.Events.Tag alias Mobilizon.Events.Tag
alias Mobilizon.Medias
alias Mobilizon.Medias.Media alias Mobilizon.Medias.Media
alias Mobilizon.Posts.Post.TitleSlug alias Mobilizon.Posts.Post.TitleSlug
alias Mobilizon.Posts.PostVisibility alias Mobilizon.Posts.PostVisibility
@ -141,6 +141,12 @@ defmodule Mobilizon.Posts.Post do
defp put_tags(changeset, _), do: changeset defp put_tags(changeset, _), do: changeset
@spec process_tag(map() | Tag.t()) :: Tag.t() | Ecto.Changeset.t()
# We need a changeset instead of a raw struct because of slug which is generated in changeset
defp process_tag(%{id: id} = _tag) do
Events.get_tag(id)
end
defp process_tag(tag), do: Tag.changeset(%Tag{}, tag) defp process_tag(tag), do: Tag.changeset(%Tag{}, tag)
defp maybe_put_publish_date(%Changeset{} = changeset) do defp maybe_put_publish_date(%Changeset{} = changeset) do