Add local visibility
This commit is contained in:
parent
c7bcbfbc1d
commit
0118ccb53c
14 changed files with 49 additions and 52 deletions
|
|
@ -19,8 +19,6 @@ defmodule Pleroma.Activity do
|
|||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
@type t :: %__MODULE__{}
|
||||
@type actor :: String.t()
|
||||
|
||||
|
|
@ -358,12 +356,4 @@ defmodule Pleroma.Activity do
|
|||
actor = user_actor(activity)
|
||||
activity.id in actor.pinned_activities
|
||||
end
|
||||
|
||||
def local_only?(activity) do
|
||||
recipients = Enum.concat(activity.data["to"], Map.get(activity.data, "cc", []))
|
||||
public = Pleroma.Constants.as_public()
|
||||
local = Pleroma.Constants.as_local_public()
|
||||
|
||||
Enum.member?(recipients, local) and not Enum.member?(recipients, public)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ defmodule Pleroma.Web.ActivityPub.Builder do
|
|||
actor.ap_id == Relay.ap_id() ->
|
||||
[actor.follower_address]
|
||||
|
||||
public? and Pleroma.Activity.local_only?(object) ->
|
||||
public? and Visibility.is_local_public?(object) ->
|
||||
[actor.follower_address, object.data["actor"], Pleroma.Constants.as_local_public()]
|
||||
|
||||
public? ->
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
|
|||
alias Pleroma.Web.ActivityPub.MRF
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
alias Pleroma.Web.ActivityPub.SideEffects
|
||||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
alias Pleroma.Web.Federator
|
||||
|
||||
@spec common_pipeline(map(), keyword()) ::
|
||||
|
|
@ -55,7 +56,7 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
|
|||
with {:ok, local} <- Keyword.fetch(meta, :local) do
|
||||
do_not_federate = meta[:do_not_federate] || !Config.get([:instance, :federating])
|
||||
|
||||
if !do_not_federate and local and not Activity.local_only?(activity) do
|
||||
if !do_not_federate and local and not Visibility.is_local_public?(activity) do
|
||||
activity =
|
||||
if object = Keyword.get(meta, :object_data) do
|
||||
%{activity | data: Map.put(activity.data, "object", object)}
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
|
||||
with true <- Config.get!([:instance, :federating]),
|
||||
true <- type != "Block" || outgoing_blocks,
|
||||
false <- Activity.local_only?(activity) do
|
||||
false <- Visibility.is_local_public?(activity) do
|
||||
Pleroma.Web.Federator.publish(activity)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,14 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
|
|||
Utils.label_in_message?(Pleroma.Constants.as_local_public(), data)
|
||||
end
|
||||
|
||||
def is_local_public?(%Object{data: data}), do: is_local_public?(data)
|
||||
def is_local_public?(%Activity{data: data}), do: is_local_public?(data)
|
||||
|
||||
def is_local_public?(data) do
|
||||
Utils.label_in_message?(Pleroma.Constants.as_local_public(), data) and
|
||||
not Utils.label_in_message?(Pleroma.Constants.as_public(), data)
|
||||
end
|
||||
|
||||
def is_private?(activity) do
|
||||
with false <- is_public?(activity),
|
||||
%User{follower_address: follower_address} <-
|
||||
|
|
@ -118,6 +126,9 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
|
|||
Pleroma.Constants.as_public() in cc ->
|
||||
"unlisted"
|
||||
|
||||
Pleroma.Constants.as_local_public() in to ->
|
||||
"local"
|
||||
|
||||
# this should use the sql for the object's activity
|
||||
Enum.any?(to, &String.contains?(&1, "/followers")) ->
|
||||
"private"
|
||||
|
|
|
|||
|
|
@ -475,10 +475,6 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
|
|||
type: :string,
|
||||
description:
|
||||
"Will reply to a given conversation, addressing only the people who are part of the recipient set of that conversation. Sets the visibility to `direct`."
|
||||
},
|
||||
local_only: %Schema{
|
||||
type: :boolean,
|
||||
description: "Post the status as local only"
|
||||
}
|
||||
},
|
||||
example: %{
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ defmodule Pleroma.Web.ApiSpec.Schemas.VisibilityScope do
|
|||
title: "VisibilityScope",
|
||||
description: "Status visibility",
|
||||
type: :string,
|
||||
enum: ["public", "unlisted", "private", "direct", "list"]
|
||||
enum: ["public", "unlisted", "local", "private", "direct", "list"]
|
||||
})
|
||||
end
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
def get_visibility(_, _, %Participation{}), do: {"direct", "direct"}
|
||||
|
||||
def get_visibility(%{visibility: visibility}, in_reply_to, _)
|
||||
when visibility in ~w{public unlisted private direct},
|
||||
when visibility in ~w{public local unlisted private direct},
|
||||
do: {visibility, get_replied_to_visibility(in_reply_to)}
|
||||
|
||||
def get_visibility(%{visibility: "list:" <> list_id}, in_reply_to, _) do
|
||||
|
|
|
|||
|
|
@ -65,8 +65,14 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
{Enum.map(participation.recipients, & &1.ap_id), []}
|
||||
end
|
||||
|
||||
def get_to_and_cc(%{visibility: "public"} = draft) do
|
||||
to = [public_uri(draft) | draft.mentions]
|
||||
def get_to_and_cc(%{visibility: visibility} = draft) when visibility in ["public", "local"] do
|
||||
|
||||
to =
|
||||
case visibility do
|
||||
"public" -> [Pleroma.Constants.as_public() | draft.mentions]
|
||||
"local" -> [Pleroma.Constants.as_local_public() | draft.mentions]
|
||||
end
|
||||
|
||||
cc = [draft.user.follower_address]
|
||||
|
||||
if draft.in_reply_to do
|
||||
|
|
@ -78,7 +84,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
|
||||
def get_to_and_cc(%{visibility: "unlisted"} = draft) do
|
||||
to = [draft.user.follower_address | draft.mentions]
|
||||
cc = [public_uri(draft)]
|
||||
cc = [Pleroma.Constants.as_public()]
|
||||
|
||||
if draft.in_reply_to do
|
||||
{Enum.uniq([draft.in_reply_to.data["actor"] | to]), cc}
|
||||
|
|
@ -103,9 +109,6 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
|
||||
def get_to_and_cc(%{visibility: {:list, _}, mentions: mentions}), do: {mentions, []}
|
||||
|
||||
defp public_uri(%{params: %{local_only: true}}), do: Pleroma.Constants.as_local_public()
|
||||
defp public_uri(_), do: Pleroma.Constants.as_public()
|
||||
|
||||
def get_addressed_users(_, to) when is_list(to) do
|
||||
User.get_ap_ids_by_nicknames(to)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -368,8 +368,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||
direct_conversation_id: direct_conversation_id,
|
||||
thread_muted: thread_muted?,
|
||||
emoji_reactions: emoji_reactions,
|
||||
parent_visible: visible_for_user?(reply_to, opts[:for]),
|
||||
local_only: Activity.local_only?(activity)
|
||||
parent_visible: visible_for_user?(reply_to, opts[:for])
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue