Use ActivityPub.get_or_fetch_actor_by_url/2 instead of

directly Actors.get_actor_by_url

So that we can refresh actors when they're stale

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-06-15 11:13:20 +02:00
parent 9063772e35
commit 5990633fb9
7 changed files with 30 additions and 21 deletions

View File

@@ -163,6 +163,7 @@ defmodule Mobilizon.Federation.ActivityPub do
end
end
@spec get_or_fetch_actor_by_url(String.t(), boolean()) :: {:ok, Actor.t()} | {:error, any()}
def get_or_fetch_actor_by_url(url, preload) do
with {:ok, %Actor{} = cached_actor} <- Actors.get_actor_by_url(url, preload),
false <- Actors.needs_update?(cached_actor) do
@@ -295,7 +296,7 @@ defmodule Mobilizon.Federation.ActivityPub do
local \\ true,
public \\ true
) do
with {:ok, %Actor{id: object_owner_actor_id}} <- Actors.get_actor_by_url(object["actor"]),
with {:ok, %Actor{id: object_owner_actor_id}} <- get_or_fetch_actor_by_url(object["actor"]),
{:ok, %Share{} = _share} <- Share.create(object["id"], actor.id, object_owner_actor_id),
announce_data <- make_announce_data(actor, object, activity_id, public),
{:ok, activity} <- create_activity(announce_data, local),