From: Egor Kislitsyn Date: Thu, 15 Oct 2020 15:07:00 +0000 (+0400) Subject: Add Pleroma.Constants.as_local_public/0 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=2a475622eea5550c9ab455c4e86212fc09ee9c58;p=akkoma Add Pleroma.Constants.as_local_public/0 --- 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 @@ defmodule Pleroma.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 @@ defmodule Pleroma.Web.ActivityPub.Builder 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 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidator 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 @@ defmodule Pleroma.Web.ActivityPub.Visibility do 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 @@ 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.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 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest 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)