Allow to refresh instance outbox when they accept subscription

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-09-02 08:59:59 +02:00
parent c011a988a8
commit 489fd74545
20 changed files with 427 additions and 227 deletions

View File

@@ -51,6 +51,8 @@ defmodule Mobilizon.Federation.ActivityPub do
require Logger
@public_ap_adress "https://www.w3.org/ns/activitystreams#Public"
@doc """
Wraps an object into an activity
"""
@@ -111,10 +113,18 @@ defmodule Mobilizon.Federation.ActivityPub do
{:ok, entity}
end
with {:ok, entity} <- res do
Logger.debug("Going to preload an existing entity")
Logger.debug("Going to preload an existing entity")
Preloader.maybe_preload(entity)
case res do
{:ok, entity} ->
Preloader.maybe_preload(entity)
{:error, status, entity} ->
{:ok, entity} = Preloader.maybe_preload(entity)
{:error, status, entity}
err ->
err
end
e ->
@@ -303,7 +313,8 @@ defmodule Mobilizon.Federation.ActivityPub do
Make an actor follow another
"""
def follow(%Actor{} = follower, %Actor{} = followed, activity_id \\ nil, local \\ true) do
with {:ok, %Follower{} = follower} <-
with {:different_actors, true} <- {:different_actors, followed.id != follower.id},
{:ok, %Follower{} = follower} <-
Actors.follow(followed, follower, activity_id, false),
follower_as_data <- Convertible.model_to_as(follower),
{:ok, activity} <- create_activity(follower_as_data, local),
@@ -312,6 +323,9 @@ defmodule Mobilizon.Federation.ActivityPub do
else
{:error, err, msg} when err in [:already_following, :suspended] ->
{:error, msg}
{:different_actors, _} ->
{:error, "Can't follow yourself"}
end
end
@@ -649,7 +663,7 @@ defmodule Mobilizon.Federation.ActivityPub do
defp convert_followers_in_recipients(recipients) do
Enum.reduce(recipients, {recipients, []}, fn recipient, {recipients, follower_actors} = acc ->
case Actors.get_group_by_followers_url(recipient) do
case Actors.get_actor_by_followers_url(recipient) do
%Actor{} = group ->
{Enum.filter(recipients, fn recipient -> recipient != group.followers_url end),
follower_actors ++ Actors.list_external_followers_for_actor(group)}
@@ -797,9 +811,9 @@ defmodule Mobilizon.Federation.ActivityPub do
@spec event_to_activity(%Event{}, boolean()) :: Activity.t()
defp event_to_activity(%Event{} = event, local \\ true) do
%Activity{
recipients: ["https://www.w3.org/ns/activitystreams#Public"],
recipients: [@public_ap_adress],
actor: event.organizer_actor.url,
data: Converter.Event.model_to_as(event),
data: event |> Convertible.model_to_as() |> make_create_data(%{"to" => @public_ap_adress}),
local: local
}
end
@@ -808,9 +822,10 @@ defmodule Mobilizon.Federation.ActivityPub do
@spec comment_to_activity(%Comment{}, boolean()) :: Activity.t()
defp comment_to_activity(%Comment{} = comment, local \\ true) do
%Activity{
recipients: ["https://www.w3.org/ns/activitystreams#Public"],
recipients: [@public_ap_adress],
actor: comment.actor.url,
data: Converter.Comment.model_to_as(comment),
data:
comment |> Convertible.model_to_as() |> make_create_data(%{"to" => @public_ap_adress}),
local: local
}
end