From 2a475622eea5550c9ab455c4e86212fc09ee9c58 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 15 Oct 2020 19:07:00 +0400 Subject: [PATCH] Add Pleroma.Constants.as_local_public/0 --- lib/pleroma/activity.ex | 2 +- lib/pleroma/constants.ex | 2 ++ lib/pleroma/web/activity_pub/builder.ex | 2 +- .../web/activity_pub/object_validators/announce_validator.ex | 2 +- lib/pleroma/web/activity_pub/visibility.ex | 2 +- lib/pleroma/web/common_api/utils.ex | 2 +- .../web/mastodon_api/controllers/status_controller_test.exs | 2 +- 7 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 789655ba2..3b01f5e31 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -349,7 +349,7 @@ def pinned_by_actor?(%Activity{} = activity) do def local_only?(activity) do recipients = Enum.concat(activity.data["to"], Map.get(activity.data, "cc", [])) public = Pleroma.Constants.as_public() - local = Pleroma.Web.base_url() <> "/#Public" + local = Pleroma.Constants.as_local_public() Enum.member?(recipients, local) and not Enum.member?(recipients, public) end diff --git a/lib/pleroma/constants.ex b/lib/pleroma/constants.ex index 13eeaa96b..cf8182d55 100644 --- a/lib/pleroma/constants.ex +++ b/lib/pleroma/constants.ex @@ -26,4 +26,6 @@ defmodule Pleroma.Constants do do: ~w(index.html robots.txt static static-fe finmoji emoji packs sounds images instance sw.js sw-pleroma.js favicon.png schemas doc embed.js embed.css) ) + + def as_local_public, do: Pleroma.Web.base_url() <> "/#Public" end diff --git a/lib/pleroma/web/activity_pub/builder.ex b/lib/pleroma/web/activity_pub/builder.ex index 236a5b9d1..c9200a3f0 100644 --- a/lib/pleroma/web/activity_pub/builder.ex +++ b/lib/pleroma/web/activity_pub/builder.ex @@ -223,7 +223,7 @@ def announce(actor, object, options \\ []) do [actor.follower_address] public? and Pleroma.Activity.local_only?(object) -> - [actor.follower_address, object.data["actor"], Pleroma.Web.base_url() <> "/#Public"] + [actor.follower_address, object.data["actor"], Pleroma.Constants.as_local_public()] public? -> [actor.follower_address, object.data["actor"], Pleroma.Constants.as_public()] diff --git a/lib/pleroma/web/activity_pub/object_validators/announce_validator.ex b/lib/pleroma/web/activity_pub/object_validators/announce_validator.ex index 5a963fca7..338957db8 100644 --- a/lib/pleroma/web/activity_pub/object_validators/announce_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/announce_validator.ex @@ -68,7 +68,7 @@ def validate_announcable(cng) do false <- Visibility.is_public?(object) do same_actor = object.data["actor"] == actor.ap_id recipients = get_field(cng, :to) ++ get_field(cng, :cc) - local_public = Pleroma.Web.base_url() <> "/#Public" + local_public = Pleroma.Constants.as_local_public() is_public = Enum.member?(recipients, Pleroma.Constants.as_public()) or diff --git a/lib/pleroma/web/activity_pub/visibility.ex b/lib/pleroma/web/activity_pub/visibility.ex index 3654b489b..1a0c9a46c 100644 --- a/lib/pleroma/web/activity_pub/visibility.ex +++ b/lib/pleroma/web/activity_pub/visibility.ex @@ -20,7 +20,7 @@ def is_public?(%{"directMessage" => true}), do: false def is_public?(data) do Utils.label_in_message?(Pleroma.Constants.as_public(), data) or - Utils.label_in_message?(Pleroma.Web.base_url() <> "/#Public", data) + Utils.label_in_message?(Pleroma.Constants.as_local_public(), data) end def is_private?(activity) do diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 7c49c1fb1..d57ba4209 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -103,7 +103,7 @@ def get_to_and_cc(%{visibility: "direct"} = draft) do def get_to_and_cc(%{visibility: {:list, _}, mentions: mentions}), do: {mentions, []} - defp public_uri(%{params: %{local_only: true}}), do: Pleroma.Web.base_url() <> "/#Public" + 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 diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs index b047f183d..4acf7a18e 100644 --- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -1752,7 +1752,7 @@ test "posting a local only status" do "local_only" => "true" }) - local = Pleroma.Web.base_url() <> "/#Public" + local = Pleroma.Constants.as_local_public() assert %{"content" => "cofe", "id" => id, "pleroma" => %{"local_only" => true}} = json_response(conn_one, 200)