Pleroma.Constants.as_local_public/0 --> Pleroma.Web.ActivityPub.Utils.as_local_public/0

Move as_local_public/0 to stop making modules depend on Web at compile-time
This commit is contained in:
Alex Gleason 2021-05-31 13:39:15 -05:00
parent b221d77a6d
commit 10dfe81479
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
7 changed files with 10 additions and 9 deletions

View file

@ -27,6 +27,4 @@ defmodule Pleroma.Constants do
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) ~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 end

View file

@ -223,7 +223,7 @@ def announce(actor, object, options \\ []) do
[actor.follower_address] [actor.follower_address]
public? and Visibility.is_local_public?(object) -> public? and Visibility.is_local_public?(object) ->
[actor.follower_address, object.data["actor"], Pleroma.Constants.as_local_public()] [actor.follower_address, object.data["actor"], Utils.as_local_public()]
public? -> public? ->
[actor.follower_address, object.data["actor"], Pleroma.Constants.as_public()] [actor.follower_address, object.data["actor"], Pleroma.Constants.as_public()]

View file

@ -68,7 +68,7 @@ def validate_announcable(cng) do
false <- Visibility.is_public?(object) do false <- Visibility.is_public?(object) do
same_actor = object.data["actor"] == actor.ap_id same_actor = object.data["actor"] == actor.ap_id
recipients = get_field(cng, :to) ++ get_field(cng, :cc) recipients = get_field(cng, :to) ++ get_field(cng, :cc)
local_public = Pleroma.Constants.as_local_public() local_public = Utils.as_local_public()
is_public = is_public =
Enum.member?(recipients, Pleroma.Constants.as_public()) or Enum.member?(recipients, Pleroma.Constants.as_public()) or

View file

@ -38,6 +38,8 @@ defmodule Pleroma.Web.ActivityPub.Utils do
@supported_report_states ~w(open closed resolved) @supported_report_states ~w(open closed resolved)
@valid_visibilities ~w(public unlisted private direct) @valid_visibilities ~w(public unlisted private direct)
def as_local_public, do: Web.base_url() <> "/#Public"
# Some implementations send the actor URI as the actor field, others send the entire actor object, # Some implementations send the actor URI as the actor field, others send the entire actor object,
# so figure out what the actor's URI is based on what we have. # so figure out what the actor's URI is based on what we have.
def get_ap_id(%{"id" => id} = _), do: id def get_ap_id(%{"id" => id} = _), do: id

View file

@ -20,14 +20,14 @@ def is_public?(%{"directMessage" => true}), do: false
def is_public?(data) do def is_public?(data) do
Utils.label_in_message?(Pleroma.Constants.as_public(), data) or Utils.label_in_message?(Pleroma.Constants.as_public(), data) or
Utils.label_in_message?(Pleroma.Constants.as_local_public(), data) Utils.label_in_message?(Utils.as_local_public(), data)
end end
def is_local_public?(%Object{data: data}), do: is_local_public?(data) 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?(%Activity{data: data}), do: is_local_public?(data)
def is_local_public?(data) do def is_local_public?(data) do
Utils.label_in_message?(Pleroma.Constants.as_local_public(), data) and Utils.label_in_message?(Utils.as_local_public(), data) and
not Utils.label_in_message?(Pleroma.Constants.as_public(), data) not Utils.label_in_message?(Pleroma.Constants.as_public(), data)
end end
@ -127,7 +127,7 @@ def get_visibility(object) do
Pleroma.Constants.as_public() in cc -> Pleroma.Constants.as_public() in cc ->
"unlisted" "unlisted"
Pleroma.Constants.as_local_public() in to -> Utils.as_local_public() in to ->
"local" "local"
# this should use the sql for the object's activity # this should use the sql for the object's activity

View file

@ -69,7 +69,7 @@ def get_to_and_cc(%{visibility: visibility} = draft) when visibility in ["public
to = to =
case visibility do case visibility do
"public" -> [Pleroma.Constants.as_public() | draft.mentions] "public" -> [Pleroma.Constants.as_public() | draft.mentions]
"local" -> [Pleroma.Constants.as_local_public() | draft.mentions] "local" -> [Utils.as_local_public() | draft.mentions]
end end
cc = [draft.user.follower_address] cc = [draft.user.follower_address]

View file

@ -14,6 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
alias Pleroma.Tests.ObanHelpers alias Pleroma.Tests.ObanHelpers
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI
import Pleroma.Factory import Pleroma.Factory
@ -1875,7 +1876,7 @@ test "posting a local only status" do
"visibility" => "local" "visibility" => "local"
}) })
local = Pleroma.Constants.as_local_public() local = Utils.as_local_public()
assert %{"content" => "cofe", "id" => id, "visibility" => "local"} = assert %{"content" => "cofe", "id" => id, "visibility" => "local"} =
json_response(conn_one, 200) json_response(conn_one, 200)