Fix fetching statuses from Mastodon

This commit is contained in:
Shadowfacts 2021-08-25 17:23:37 -04:00
parent afff7c4fb3
commit ef3b435a8d
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 7 additions and 1 deletions

View File

@ -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