"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, %User{} = user} <- ObjectValidator.fetch_actor(data),
- # maybe locally user doesn't have featured_address
- {:ok, user} <- maybe_refetch_user(user),
- %Object{} <- Object.normalize(data["object"], fetch: true) do
- # Mastodon sends pin/unpin objects without id, to, cc fields
- data =
- data
- |> Map.put_new("id", Utils.generate_activity_id())
- |> Map.put_new("to", [Pleroma.Constants.as_public()])
- |> Map.put_new("cc", [user.follower_address])
-
- case Pipeline.common_pipeline(data,
- local: false,
- featured_address: user.featured_address
- ) do
- {:ok, activity, _meta} -> {:ok, activity}
- error -> error
- end
- 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)