Prevent picture resend on event update, handle duplicate pictures

properly in backend and add a proper default picture

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-10-14 11:41:57 +02:00
parent 18cabe4d42
commit cbe1dd2868
9 changed files with 45 additions and 23 deletions

View File

@@ -20,7 +20,7 @@ defmodule MobilizonWeb.Schema.PictureType do
# Either a full picture object
field(:picture, :picture_input_object)
# Or directly the ID of an existing picture
field(:picture_id, :string)
field(:picture_id, :id)
end
@desc "An attached picture"

View File

@@ -261,6 +261,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
def make_picture_data(picture) when is_map(picture) do
with {:ok, %{"url" => [%{"href" => url, "mediaType" => content_type}], "size" => size}} <-
MobilizonWeb.Upload.store(picture.file),
{:picture_exists, nil} <- {:picture_exists, Mobilizon.Media.get_picture_by_url(url)},
{:ok, %Picture{file: _file} = picture} <-
Mobilizon.Media.create_picture(%{
"file" => %{
@@ -272,6 +273,12 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
"actor_id" => picture.actor_id
}) do
Converter.Picture.model_to_as(picture)
else
{:picture_exists, %Picture{file: _file} = picture} ->
Converter.Picture.model_to_as(picture)
err ->
err
end
end