From ef3b435a8de15c6e87e9d8b0c752682f336ff4dd Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 25 Aug 2021 17:23:37 -0400 Subject: [PATCH] Fix fetching statuses from Mastodon --- lib/clacks/activitypub/fetcher.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/clacks/activitypub/fetcher.ex b/lib/clacks/activitypub/fetcher.ex index 0ccf273..3832baf 100644 --- a/lib/clacks/activitypub/fetcher.ex +++ b/lib/clacks/activitypub/fetcher.ex @@ -19,7 +19,8 @@ defmodule Clacks.ActivityPub.Fetcher do def fetch_object(id) do %{host: id_host} = URI.parse(id) - with %{"actor" => remote_actor} = object <- fetch(id), + with object when is_map(object) <- fetch(id), + remote_actor when is_binary(remote_actor) <- get_actor(object), %{host: ^id_host} <- URI.parse(remote_actor) do object else @@ -48,4 +49,9 @@ defmodule Clacks.ActivityPub.Fetcher do nil end end + + @spec get_actor(data :: map()) :: String.t() | nil + defp get_actor(%{"actor" => actor}) when is_binary(actor), do: actor + defp get_actor(%{"attributedTo" => actor}) when is_binary(actor), do: actor + defp get_actor(_), do: nil end