"type" => Map.get(url || %{}, "type", "Link")
}
|> Maps.put_if_present("mediaType", media_type)
+ |> Maps.put_if_present("width", (url || %{})["width"] || data["width"])
+ |> Maps.put_if_present("height", (url || %{})["height"] || data["height"])
%{
"url" => [attachment_url],
end
def handle_incoming(%{"type" => type} = data, _options)
- when type in ~w{Like EmojiReact Announce} do
+ when type in ~w{Like EmojiReact Announce Add Remove} do
with :ok <- ObjectValidator.fetch_actor_and_object(data),
{:ok, activity, _meta} <-
Pipeline.common_pipeline(data, local: false) do
end
end
- def handle_incoming(%{"type" => type} = data, _options) when type in ~w(Add Remove) do
- with :ok <- ObjectValidator.fetch_actor_and_object(data),
- {:ok, actor} <- Pleroma.User.get_or_fetch_by_ap_id(data["actor"]),
- # maybe locally user doesn't have featured_address
- {:ok, _} <- maybe_refetch_user(actor),
- {:ok, activity, _meta} <- Pipeline.common_pipeline(data, local: false) do
- {:ok, activity}
- end
- end
-
def handle_incoming(
%{"type" => "Delete"} = data,
_options
Pipeline.common_pipeline(data, local: false) do
{:ok, activity}
else
- {:error, {:validate_object, _}} = e ->
+ {:error, {:validate, _}} = e ->
# Check if we have a create activity for this
with {:ok, object_id} <- ObjectValidators.ObjectID.cast(data["object"]),
%Activity{data: %{"actor" => actor}} <-
def handle_incoming(_, _), do: :error
- defp maybe_refetch_user(%User{featured_address: address} = user) when is_binary(address) do
- {:ok, user}
- end
-
- defp maybe_refetch_user(%User{ap_id: ap_id}), do: upgrade_user_from_ap_id(ap_id)
-
@spec get_obj_helper(String.t(), Keyword.t()) :: {:ok, Object.t()} | nil
def get_obj_helper(id, options \\ []) do
options = Keyword.put(options, :fetch, true)
object
|> Map.get("attachment", [])
|> Enum.map(fn data ->
- [%{"mediaType" => media_type, "href" => href} | _] = data["url"]
+ [%{"mediaType" => media_type, "href" => href} = url | _] = data["url"]
%{
"url" => href,
"name" => data["name"],
"type" => "Document"
}
+ |> Maps.put_if_present("width", url["width"])
+ |> Maps.put_if_present("height", url["height"])
+ |> Maps.put_if_present("blurhash", data["blurhash"])
end)
Map.put(object, "attachment", attachments)