From d609ccfb514642cbd59dfae9d6537d6c1a61731d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 4 Jul 2019 17:41:06 +0200 Subject: [PATCH] Upload pictures fixes Signed-off-by: Thomas Citharel --- lib/mobilizon_web/api/events.ex | 3 ++- lib/mobilizon_web/resolvers/event.ex | 7 ++++++- lib/service/activity_pub/utils.ex | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/mobilizon_web/api/events.ex b/lib/mobilizon_web/api/events.ex index 58307d49f..7adb7ac01 100644 --- a/lib/mobilizon_web/api/events.ex +++ b/lib/mobilizon_web/api/events.ex @@ -22,7 +22,8 @@ defmodule MobilizonWeb.API.Events do category: category } = args ) do - with %Actor{url: url} = actor <- Actors.get_local_actor_with_everything(organizer_actor_id), + with %Actor{url: url} = actor <- + Actors.get_local_actor_with_everything(organizer_actor_id), title <- String.trim(title), mentions <- Formatter.parse_mentions(description), visibility <- Map.get(args, :visibility, "public"), diff --git a/lib/mobilizon_web/resolvers/event.ex b/lib/mobilizon_web/resolvers/event.ex index 3f0c3f29d..c53a47a86 100644 --- a/lib/mobilizon_web/resolvers/event.ex +++ b/lib/mobilizon_web/resolvers/event.ex @@ -217,8 +217,13 @@ defmodule MobilizonWeb.Resolvers.Event do # If we have an attached picture, just transmit it. It will be handled by # Mobilizon.Service.ActivityPub.Utils.make_picture_data/1 + # However, we need to pass it's actor ID @spec save_attached_picture(map()) :: {:ok, map()} - defp save_attached_picture(%{picture: %{picture: %Plug.Upload{} = _picture}} = args), do: args + defp save_attached_picture( + %{picture: %{picture: %{file: %Plug.Upload{} = _picture} = all_pic}} = args + ) do + {:ok, Map.put(args, :picture, Map.put(all_pic, :actor_id, args.organizer_actor_id))} + end # Otherwise if we use a previously uploaded picture we need to fetch it from database @spec save_attached_picture(map()) :: {:ok, map()} diff --git a/lib/service/activity_pub/utils.ex b/lib/service/activity_pub/utils.ex index fdd469eee..7c02e82a9 100644 --- a/lib/service/activity_pub/utils.ex +++ b/lib/service/activity_pub/utils.ex @@ -208,7 +208,7 @@ defmodule Mobilizon.Service.ActivityPub.Utils do @doc """ Save picture data from raw data and return AS Link data. """ - def make_picture_data(%{picture: picture}) 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), {:ok, %Picture{file: _file} = pic} <-