Only federate group draft posts to members
Closes #615 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -710,7 +710,7 @@ defmodule Mobilizon.Federation.ActivityPub do
|
||||
@spec publish(Actor.t(), Activity.t()) :: :ok
|
||||
def publish(actor, %Activity{recipients: recipients} = activity) do
|
||||
Logger.debug("Publishing an activity")
|
||||
Logger.debug(inspect(activity))
|
||||
Logger.debug(inspect(activity, pretty: true))
|
||||
|
||||
public = Visibility.is_public?(activity)
|
||||
Logger.debug("is public ? #{public}")
|
||||
|
||||
@@ -123,19 +123,29 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||
end
|
||||
|
||||
def calculate_to_and_cc_from_mentions(%Post{
|
||||
attributed_to: %Actor{members_url: members_url},
|
||||
visibility: visibility
|
||||
attributed_to: %Actor{members_url: members_url, followers_url: followers_url},
|
||||
visibility: visibility,
|
||||
draft: draft
|
||||
}) do
|
||||
case visibility do
|
||||
:public ->
|
||||
%{"to" => [@ap_public, members_url], "cc" => []}
|
||||
cond do
|
||||
# If the post is draft we send it only to members
|
||||
draft == true ->
|
||||
%{"to" => [members_url], "cc" => []}
|
||||
|
||||
:unlisted ->
|
||||
%{"to" => [members_url], "cc" => [@ap_public]}
|
||||
# If public everyone
|
||||
visibility == :public ->
|
||||
%{"to" => [@ap_public, members_url], "cc" => [followers_url]}
|
||||
|
||||
:private ->
|
||||
# Otherwise just followers
|
||||
visibility == :unlisted ->
|
||||
%{"to" => [followers_url, members_url], "cc" => [@ap_public]}
|
||||
|
||||
visibility == :private ->
|
||||
# Private is restricted to only the members
|
||||
%{"to" => [members_url], "cc" => []}
|
||||
|
||||
true ->
|
||||
%{"to" => [], "cc" => []}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -24,10 +24,8 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Posts do
|
||||
{:ok, %Actor{} = group} <- Actors.get_group_by_actor_id(group_id),
|
||||
%Actor{} = creator <- Actors.get_actor(creator_id),
|
||||
post_as_data <-
|
||||
Convertible.model_to_as(%{post | attributed_to: group, author: creator}),
|
||||
audience <-
|
||||
Audience.calculate_to_and_cc_from_mentions(post) do
|
||||
create_data = make_create_data(post_as_data, Map.merge(audience, additional))
|
||||
Convertible.model_to_as(%{post | attributed_to: group, author: creator}) do
|
||||
create_data = make_create_data(post_as_data, additional)
|
||||
|
||||
{:ok, post, create_data}
|
||||
else
|
||||
|
||||
@@ -421,7 +421,13 @@ defmodule Mobilizon.Federation.ActivityPub.Utils do
|
||||
["https://www.w3.org/ns/activitystreams#Public"]}
|
||||
else
|
||||
if actor_type == :Group do
|
||||
{[actor.followers_url, actor.members_url], []}
|
||||
to =
|
||||
(object["to"] || [])
|
||||
|> MapSet.new()
|
||||
|> MapSet.intersection(MapSet.new([actor.followers_url, actor.members_url]))
|
||||
|> MapSet.to_list()
|
||||
|
||||
{to, []}
|
||||
else
|
||||
{[actor.followers_url], []}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user