@@ -45,8 +45,12 @@ defmodule Mobilizon.Federation.ActivityPub.Publisher do
|
||||
|
||||
{recipients, followers} = convert_followers_in_recipients(recipients)
|
||||
|
||||
Logger.debug("Found the following followers: #{inspect(Enum.map(followers, & &1.url))}")
|
||||
|
||||
{recipients, members} = convert_members_in_recipients(recipients)
|
||||
|
||||
Logger.debug("Found the following followers: #{inspect(Enum.map(members, & &1.url))}")
|
||||
|
||||
remote_inboxes =
|
||||
(remote_actors(recipients) ++ followers ++ members)
|
||||
|> Enum.map(fn actor -> actor.shared_inbox_url || actor.inbox_url end)
|
||||
|
||||
@@ -192,6 +192,8 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
_attributed_to
|
||||
)
|
||||
when is_map(object) do
|
||||
Logger.debug("Maybe relay if group activity (object is map)")
|
||||
Logger.debug(inspect(object))
|
||||
do_maybe_relay_if_group_activity(object, object["attributedTo"])
|
||||
end
|
||||
|
||||
@@ -201,10 +203,12 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
%Actor{url: attributed_to_url}
|
||||
)
|
||||
when is_binary(object) and is_binary(attributed_to_url) do
|
||||
Logger.debug("Maybe relay if group activity (object is binary)")
|
||||
do_maybe_relay_if_group_activity(object, attributed_to_url)
|
||||
end
|
||||
|
||||
def maybe_relay_if_group_activity(_activity, _attributedTo) do
|
||||
Logger.debug("Will not replay : not a group activity")
|
||||
:ok
|
||||
end
|
||||
|
||||
@@ -214,6 +218,7 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
do: do_maybe_relay_if_group_activity(object, hd(attributed_to))
|
||||
|
||||
defp do_maybe_relay_if_group_activity(object, attributed_to) when is_binary(attributed_to) do
|
||||
Logger.debug("Let's try to relay group activity")
|
||||
id = "#{Endpoint.url()}/announces/#{Ecto.UUID.generate()}"
|
||||
|
||||
case Actors.get_local_group_by_url(attributed_to) do
|
||||
@@ -223,8 +228,9 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
Logger.info("Forwarded activity to external members of the group")
|
||||
:ok
|
||||
|
||||
{:error, _err} ->
|
||||
{:error, err} ->
|
||||
Logger.info("Failed to forward activity to external members of the group")
|
||||
Logger.debug(inspect(err))
|
||||
:error
|
||||
end
|
||||
|
||||
@@ -233,7 +239,9 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
end
|
||||
end
|
||||
|
||||
defp do_maybe_relay_if_group_activity(_, _), do: :ok
|
||||
defp do_maybe_relay_if_group_activity(_, attributed_to) do
|
||||
Logger.debug("Will not relay group activity, attributed to is : #{inspect(attributed_to)}")
|
||||
end
|
||||
|
||||
@spec remote_actors(list(String.t())) :: list(Actor.t())
|
||||
def remote_actors(recipients) do
|
||||
@@ -439,10 +447,16 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
) do
|
||||
{to, cc} =
|
||||
if public do
|
||||
Logger.debug("Making announce data for a public object")
|
||||
|
||||
{[actor.followers_url, object_actor_url],
|
||||
["https://www.w3.org/ns/activitystreams#Public"]}
|
||||
else
|
||||
Logger.debug("Making announce data for a private object")
|
||||
|
||||
if actor_type == :Group do
|
||||
Logger.debug("Making announce data for a group private object")
|
||||
|
||||
to =
|
||||
(object["to"] || [])
|
||||
|> MapSet.new()
|
||||
@@ -451,6 +465,7 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
|
||||
{to, []}
|
||||
else
|
||||
Logger.debug("Making announce data for a private object")
|
||||
{[actor.followers_url], []}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -196,6 +196,10 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Comment do
|
||||
|> Map.put(:origin_comment_id, origin_comment_id)
|
||||
|> Map.put(:discussion_id, discussion_id)
|
||||
|
||||
# Reply to a deleted entity
|
||||
{:ok, %Mobilizon.Tombstone{}} ->
|
||||
data
|
||||
|
||||
# Anything else is kind of a MP
|
||||
{:error, parent} ->
|
||||
Logger.warn("Parent object is something we don't handle")
|
||||
|
||||
@@ -10,7 +10,6 @@ defmodule Mobilizon.Federation.HTTPSignatures.Signature do
|
||||
|
||||
@behaviour HTTPSignatures.Adapter
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
|
||||
|
||||
@@ -53,16 +52,8 @@ defmodule Mobilizon.Federation.HTTPSignatures.Signature do
|
||||
{:ok, String.t()}
|
||||
| {:error, :actor_not_found | :pem_decode_error}
|
||||
defp get_public_key_for_url(url) do
|
||||
case Actors.get_actor_by_url(url) do
|
||||
{:ok, %Actor{} = actor} ->
|
||||
get_actor_public_key(actor)
|
||||
|
||||
{:error, :actor_not_found} ->
|
||||
Logger.info(
|
||||
"Unable to get actor with URL #{url} from local database, returning empty keys to trigger refreshment"
|
||||
)
|
||||
|
||||
{:ok, ""}
|
||||
with {:ok, %Actor{} = actor} <- ActivityPubActor.get_or_fetch_actor_by_url(url) do
|
||||
get_actor_public_key(actor)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ defmodule Mobilizon.Web.Plugs.MappedSignatureToIdentity do
|
||||
|
||||
import Plug.Conn
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
|
||||
alias Mobilizon.Federation.ActivityPub.Utils
|
||||
alias Mobilizon.Federation.HTTPSignatures.Signature
|
||||
|
||||
@@ -41,7 +41,7 @@ defmodule Mobilizon.Web.Plugs.MappedSignatureToIdentity do
|
||||
# We don't need to call refreshment here since
|
||||
# the Mobilizon.Federation.HTTPSignatures.Signature plug
|
||||
# should already have refreshed the actor if needed
|
||||
ActivityPubActor.make_actor_from_url(key_actor_id, ignore_sign_object_fetches: true)
|
||||
Actors.get_actor_by_url(key_actor_id)
|
||||
|
||||
nil ->
|
||||
{:error, :no_key_in_conn}
|
||||
|
||||
Reference in New Issue
Block a user