Update Instance Actor when updating instance settings
Also fix an issue when publishing activities to followers/group members Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -720,7 +720,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
"""
|
||||
# credo:disable-for-lines:47
|
||||
@spec publish(Actor.t(), Activity.t()) :: :ok
|
||||
def publish(actor, activity) do
|
||||
def publish(actor, %Activity{recipients: recipients} = activity) do
|
||||
Logger.debug("Publishing an activity")
|
||||
Logger.debug(inspect(activity))
|
||||
|
||||
@@ -733,24 +733,26 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
Relay.publish(activity)
|
||||
end
|
||||
|
||||
followers =
|
||||
{recipients, followers} =
|
||||
if actor.followers_url in activity.recipients do
|
||||
Actors.list_external_followers_for_actor(actor)
|
||||
{Enum.filter(recipients, fn recipient -> recipient != actor.followers_url end),
|
||||
Actors.list_external_followers_for_actor(actor)}
|
||||
else
|
||||
[]
|
||||
{recipients, []}
|
||||
end
|
||||
|
||||
# If we want to send to all members of the group, because this server is the one the group is on
|
||||
members =
|
||||
{recipients, members} =
|
||||
if is_announce_activity?(activity) and actor.type == :Group and
|
||||
actor.members_url in activity.recipients and is_nil(actor.domain) do
|
||||
Actors.list_external_members_for_group(actor)
|
||||
{Enum.filter(recipients, fn recipient -> recipient != actor.members_url end),
|
||||
Actors.list_external_members_for_group(actor)}
|
||||
else
|
||||
[]
|
||||
{recipients, []}
|
||||
end
|
||||
|
||||
remote_inboxes =
|
||||
(remote_actors(activity) ++ followers ++ members)
|
||||
(remote_actors(recipients) ++ followers ++ members)
|
||||
|> Enum.map(fn follower -> follower.shared_inbox_url || follower.inbox_url end)
|
||||
|> Enum.uniq()
|
||||
|
||||
@@ -1045,7 +1047,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
end
|
||||
end
|
||||
|
||||
@spec update_actor(Todo.t(), map, map) :: {:ok, Todo.t(), Activity.t()} | any
|
||||
@spec update_todo(Todo.t(), map, map) :: {:ok, Todo.t(), Activity.t()} | any
|
||||
defp update_todo(%Todo{} = old_todo, args, additional) do
|
||||
with {:ok, %Todo{todo_list_id: todo_list_id} = todo} <- Todos.update_todo(old_todo, args),
|
||||
%TodoList{actor_id: group_id} = todo_list <- Todos.get_todo_list(todo_list_id),
|
||||
|
||||
@@ -114,10 +114,9 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
|
||||
def maybe_federate(_), do: :ok
|
||||
|
||||
def remote_actors(%{data: %{"to" => to} = data}) do
|
||||
to = to ++ (data["cc"] || [])
|
||||
|
||||
to
|
||||
@spec remote_actors(list(String.t())) :: list(Actor.t())
|
||||
def remote_actors(recipients) do
|
||||
recipients
|
||||
|> Enum.map(fn url -> ActivityPub.get_or_fetch_actor_by_url(url) end)
|
||||
|> Enum.map(fn {status, actor} ->
|
||||
case status do
|
||||
|
||||
@@ -21,12 +21,14 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
|
||||
defdelegate model_to_as(actor), to: ActorConverter
|
||||
end
|
||||
|
||||
@allowed_types ["Application", "Group", "Organization", "Person", "Service"]
|
||||
|
||||
@doc """
|
||||
Converts an AP object data to our internal data structure.
|
||||
"""
|
||||
@impl Converter
|
||||
@spec as_to_model_data(map()) :: {:ok, map()}
|
||||
def as_to_model_data(data) do
|
||||
def as_to_model_data(%{"type" => type} = data) when type in @allowed_types do
|
||||
avatar =
|
||||
data["icon"]["url"] &&
|
||||
%{
|
||||
@@ -62,6 +64,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
|
||||
}
|
||||
end
|
||||
|
||||
def as_to_model_data(_), do: :error
|
||||
|
||||
@doc """
|
||||
Convert an actor struct to an ActivityStream representation.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user