Credo.Check.Readability.PredicateFunctionNames
This check was recently improved in Credo and it does make sense for readability. The offending functions in Pleroma have been renamed and a couple missing the ? suffix have been fixed as well.
This commit is contained in:
parent
18d38486a5
commit
5b95abaeea
@ -57,7 +57,7 @@ defmodule Pleroma.Conversation do
|
||||
3. Bump all relevant participations to 'unread'
|
||||
"""
|
||||
def create_or_bump_for(activity, opts \\ []) do
|
||||
with true <- Pleroma.Web.ActivityPub.Visibility.is_direct?(activity),
|
||||
with true <- Pleroma.Web.ActivityPub.Visibility.direct?(activity),
|
||||
"Create" <- activity.data["type"],
|
||||
%Object{} = object <- Object.normalize(activity, fetch: false),
|
||||
true <- object.data["type"] in ["Note", "Question"],
|
||||
|
@ -138,23 +138,23 @@ defmodule Pleroma.Emoji do
|
||||
emojis = emojis ++ regional_indicators
|
||||
|
||||
for emoji <- emojis do
|
||||
def is_unicode_emoji?(unquote(emoji)), do: true
|
||||
def unicode?(unquote(emoji)), do: true
|
||||
end
|
||||
|
||||
def is_unicode_emoji?(_), do: false
|
||||
def unicode?(_), do: false
|
||||
|
||||
@emoji_regex ~r/:[A-Za-z0-9_-]+(@.+)?:/
|
||||
|
||||
def is_custom_emoji?(s) when is_binary(s), do: Regex.match?(@emoji_regex, s)
|
||||
def custom?(s) when is_binary(s), do: Regex.match?(@emoji_regex, s)
|
||||
|
||||
def is_custom_emoji?(_), do: false
|
||||
def custom?(_), do: false
|
||||
|
||||
def maybe_strip_name(name) when is_binary(name), do: String.trim(name, ":")
|
||||
|
||||
def maybe_strip_name(name), do: name
|
||||
|
||||
def maybe_quote(name) when is_binary(name) do
|
||||
if is_unicode_emoji?(name) do
|
||||
if unicode?(name) do
|
||||
name
|
||||
else
|
||||
if String.starts_with?(name, ":") do
|
||||
|
@ -114,7 +114,7 @@ defmodule Pleroma.Gopher.Server.ProtocolHandler do
|
||||
|
||||
def response("/notices/" <> id) do
|
||||
with %Activity{} = activity <- Activity.get_by_id(id),
|
||||
true <- Visibility.is_public?(activity) do
|
||||
true <- Visibility.public?(activity) do
|
||||
activities =
|
||||
ActivityPub.fetch_activities_for_context(activity.data["context"])
|
||||
|> render_activities
|
||||
|
@ -2404,9 +2404,9 @@ defmodule Pleroma.User do
|
||||
|
||||
defp put_password_hash(changeset), do: changeset
|
||||
|
||||
def is_internal_user?(%User{nickname: nil}), do: true
|
||||
def is_internal_user?(%User{local: true, nickname: "internal." <> _}), do: true
|
||||
def is_internal_user?(_), do: false
|
||||
def internal?(%User{nickname: nil}), do: true
|
||||
def internal?(%User{local: true, nickname: "internal." <> _}), do: true
|
||||
def internal?(_), do: false
|
||||
|
||||
# A hack because user delete activities have a fake id for whatever reason
|
||||
# TODO: Get rid of this
|
||||
|
@ -74,22 +74,22 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||
defp check_remote_limit(_), do: true
|
||||
|
||||
def increase_note_count_if_public(actor, object) do
|
||||
if is_public?(object), do: User.increase_note_count(actor), else: {:ok, actor}
|
||||
if public?(object), do: User.increase_note_count(actor), else: {:ok, actor}
|
||||
end
|
||||
|
||||
def decrease_note_count_if_public(actor, object) do
|
||||
if is_public?(object), do: User.decrease_note_count(actor), else: {:ok, actor}
|
||||
if public?(object), do: User.decrease_note_count(actor), else: {:ok, actor}
|
||||
end
|
||||
|
||||
def update_last_status_at_if_public(actor, object) do
|
||||
if is_public?(object), do: User.update_last_status_at(actor), else: {:ok, actor}
|
||||
if public?(object), do: User.update_last_status_at(actor), else: {:ok, actor}
|
||||
end
|
||||
|
||||
defp increase_replies_count_if_reply(%{
|
||||
"object" => %{"inReplyTo" => reply_ap_id} = object,
|
||||
"type" => "Create"
|
||||
}) do
|
||||
if is_public?(object) do
|
||||
if public?(object) do
|
||||
Object.increase_replies_count(reply_ap_id)
|
||||
end
|
||||
end
|
||||
@ -100,7 +100,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||
"object" => %{"quoteUrl" => quote_ap_id} = object,
|
||||
"type" => "Create"
|
||||
}) do
|
||||
if is_public?(object) do
|
||||
if public?(object) do
|
||||
Object.increase_quotes_count(quote_ap_id)
|
||||
end
|
||||
end
|
||||
|
@ -132,7 +132,7 @@ defmodule Pleroma.Web.ActivityPub.Builder do
|
||||
def emoji_react(actor, object, emoji) do
|
||||
with {:ok, data, meta} <- object_action(actor, object) do
|
||||
data =
|
||||
if Emoji.is_unicode_emoji?(emoji) do
|
||||
if Emoji.unicode?(emoji) do
|
||||
unicode_emoji_react(object, data, emoji)
|
||||
else
|
||||
custom_emoji_react(object, data, emoji)
|
||||
@ -348,7 +348,7 @@ defmodule Pleroma.Web.ActivityPub.Builder do
|
||||
actor.ap_id == Relay.ap_id() ->
|
||||
[actor.follower_address]
|
||||
|
||||
public? and Visibility.is_local_public?(object) ->
|
||||
public? and Visibility.local_public?(object) ->
|
||||
[actor.follower_address, object.data["actor"], Utils.as_local_public()]
|
||||
|
||||
public? ->
|
||||
@ -376,7 +376,7 @@ defmodule Pleroma.Web.ActivityPub.Builder do
|
||||
|
||||
# Address the actor of the object, and our actor's follower collection if the post is public.
|
||||
to =
|
||||
if Visibility.is_public?(object) do
|
||||
if Visibility.public?(object) do
|
||||
[actor.follower_address, object.data["actor"]]
|
||||
else
|
||||
[object.data["actor"]]
|
||||
|
@ -10,9 +10,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy do
|
||||
|
||||
@impl true
|
||||
def filter(%{"actor" => actor} = object) do
|
||||
with true <- is_local?(actor),
|
||||
true <- is_eligible_type?(object),
|
||||
true <- is_note?(object),
|
||||
with true <- local?(actor),
|
||||
true <- eligible_type?(object),
|
||||
true <- note?(object),
|
||||
false <- has_attachment?(object),
|
||||
true <- only_mentions?(object) do
|
||||
{:reject, "[NoEmptyPolicy]"}
|
||||
@ -24,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy do
|
||||
|
||||
def filter(object), do: {:ok, object}
|
||||
|
||||
defp is_local?(actor) do
|
||||
defp local?(actor) do
|
||||
if actor |> String.starts_with?("#{Endpoint.url()}") do
|
||||
true
|
||||
else
|
||||
@ -59,11 +59,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy do
|
||||
|
||||
defp only_mentions?(_), do: false
|
||||
|
||||
defp is_note?(%{"object" => %{"type" => "Note"}}), do: true
|
||||
defp is_note?(_), do: false
|
||||
defp note?(%{"object" => %{"type" => "Note"}}), do: true
|
||||
defp note?(_), do: false
|
||||
|
||||
defp is_eligible_type?(%{"type" => type}) when type in ["Create", "Update"], do: true
|
||||
defp is_eligible_type?(_), do: false
|
||||
defp eligible_type?(%{"type" => type}) when type in ["Create", "Update"], do: true
|
||||
defp eligible_type?(_), do: false
|
||||
|
||||
@impl true
|
||||
def describe, do: {:ok, %{}}
|
||||
|
@ -28,7 +28,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.QuoteToLinkTagPolicy do
|
||||
tags = object["tag"] || []
|
||||
|
||||
if Enum.any?(tags, fn tag ->
|
||||
CommonFixes.is_object_link_tag(tag) and tag["href"] == quote_url
|
||||
CommonFixes.object_link_tag?(tag) and tag["href"] == quote_url
|
||||
end) do
|
||||
object
|
||||
else
|
||||
|
@ -82,7 +82,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidator do
|
||||
object when is_binary(object) <- get_field(cng, :object),
|
||||
%User{} = actor <- User.get_cached_by_ap_id(actor),
|
||||
%Object{} = object <- Object.get_cached_by_ap_id(object),
|
||||
false <- Visibility.is_public?(object) do
|
||||
false <- Visibility.public?(object) do
|
||||
same_actor = object.data["actor"] == actor.ap_id
|
||||
recipients = get_field(cng, :to) ++ get_field(cng, :cc)
|
||||
local_public = Utils.as_local_public()
|
||||
|
@ -99,7 +99,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
|
||||
end
|
||||
|
||||
def fix_quote_url(%{"tag" => [_ | _] = tags} = data) do
|
||||
tag = Enum.find(tags, &is_object_link_tag/1)
|
||||
tag = Enum.find(tags, &object_link_tag?/1)
|
||||
|
||||
if not is_nil(tag) do
|
||||
data
|
||||
@ -112,7 +112,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
|
||||
def fix_quote_url(data), do: data
|
||||
|
||||
# https://codeberg.org/fediverse/fep/src/branch/main/fep/e232/fep-e232.md
|
||||
def is_object_link_tag(%{
|
||||
def object_link_tag?(%{
|
||||
"type" => "Link",
|
||||
"mediaType" => media_type,
|
||||
"href" => href
|
||||
@ -121,5 +121,5 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
|
||||
true
|
||||
end
|
||||
|
||||
def is_object_link_tag(_), do: false
|
||||
def object_link_tag?(_), do: false
|
||||
end
|
||||
|
@ -74,10 +74,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
|
||||
new_emoji = Pleroma.Emoji.fully_qualify_emoji(emoji)
|
||||
|
||||
cond do
|
||||
Pleroma.Emoji.is_unicode_emoji?(emoji) ->
|
||||
Pleroma.Emoji.unicode?(emoji) ->
|
||||
data
|
||||
|
||||
Pleroma.Emoji.is_unicode_emoji?(new_emoji) ->
|
||||
Pleroma.Emoji.unicode?(new_emoji) ->
|
||||
data |> Map.put("content", new_emoji)
|
||||
|
||||
true ->
|
||||
@ -90,7 +90,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
|
||||
defp validate_emoji(cng) do
|
||||
content = get_field(cng, :content)
|
||||
|
||||
if Emoji.is_unicode_emoji?(content) || Emoji.is_custom_emoji?(content) do
|
||||
if Emoji.unicode?(content) || Emoji.custom?(content) do
|
||||
cng
|
||||
else
|
||||
cng
|
||||
@ -101,7 +101,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
|
||||
defp maybe_validate_tag_presence(cng) do
|
||||
content = get_field(cng, :content)
|
||||
|
||||
if Emoji.is_unicode_emoji?(content) do
|
||||
if Emoji.unicode?(content) do
|
||||
cng
|
||||
else
|
||||
tag = get_field(cng, :tag)
|
||||
|
@ -62,7 +62,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 Visibility.is_local_public?(activity) do
|
||||
if !do_not_federate and local and not Visibility.local_public?(activity) do
|
||||
activity =
|
||||
if object = Keyword.get(meta, :object_data) do
|
||||
%{activity | data: Map.put(activity.data, "object", object)}
|
||||
|
@ -66,7 +66,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
|
||||
@doc """
|
||||
Determine if an activity can be represented by running it through Transmogrifier.
|
||||
"""
|
||||
def is_representable?(%Activity{} = activity) do
|
||||
def representable?(%Activity{} = activity) do
|
||||
with {:ok, _data} <- Transmogrifier.prepare_outgoing(activity.data) do
|
||||
true
|
||||
else
|
||||
@ -246,7 +246,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
|
||||
|
||||
def publish(%User{} = actor, %{data: %{"bcc" => bcc}} = activity)
|
||||
when is_list(bcc) and bcc != [] do
|
||||
public = is_public?(activity)
|
||||
public = public?(activity)
|
||||
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
[priority_recipients, recipients] = recipients(actor, activity)
|
||||
@ -291,7 +291,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
|
||||
|
||||
# Publishes an activity to all relevant peers.
|
||||
def publish(%User{} = actor, %Activity{} = activity) do
|
||||
public = is_public?(activity)
|
||||
public = public?(activity)
|
||||
|
||||
if public && Config.get([:instance, :allow_relay]) do
|
||||
Logger.debug(fn -> "Relaying #{activity.data["id"]} out" end)
|
||||
|
@ -58,7 +58,7 @@ defmodule Pleroma.Web.ActivityPub.Relay do
|
||||
@spec publish(any()) :: {:ok, Activity.t()} | {:error, any()}
|
||||
def publish(%Activity{data: %{"type" => "Create"}} = activity) do
|
||||
with %User{} = user <- get_actor(),
|
||||
true <- Visibility.is_public?(activity) do
|
||||
true <- Visibility.public?(activity) do
|
||||
CommonAPI.repeat(activity.id, user)
|
||||
else
|
||||
error -> format_error(error)
|
||||
|
@ -258,7 +258,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||
|
||||
Utils.add_announce_to_object(object, announced_object)
|
||||
|
||||
if !User.is_internal_user?(user) do
|
||||
if !User.internal?(user) do
|
||||
Notification.create_notifications(object)
|
||||
|
||||
ap_streamer().stream_out(object)
|
||||
|
@ -783,7 +783,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||
|> Object.normalize(fetch: false)
|
||||
|
||||
data =
|
||||
if Visibility.is_private?(object) && object.data["actor"] == ap_id do
|
||||
if Visibility.private?(object) && object.data["actor"] == ap_id do
|
||||
data |> Map.put("object", object |> Map.get(:data) |> prepare_object)
|
||||
else
|
||||
data |> maybe_fix_object_url
|
||||
|
@ -167,7 +167,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
||||
|
||||
with true <- Config.get!([:instance, :federating]),
|
||||
true <- type != "Block" || outgoing_blocks,
|
||||
false <- Visibility.is_local_public?(activity) do
|
||||
false <- Visibility.local_public?(activity) do
|
||||
Pleroma.Web.Federator.publish(activity)
|
||||
end
|
||||
|
||||
@ -277,7 +277,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
||||
object_actor = User.get_cached_by_ap_id(object_actor_id)
|
||||
|
||||
to =
|
||||
if Visibility.is_public?(object) do
|
||||
if Visibility.public?(object) do
|
||||
[actor.follower_address, object.data["actor"]]
|
||||
else
|
||||
[object.data["actor"]]
|
||||
|
@ -11,28 +11,28 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
@spec is_public?(Object.t() | Activity.t() | map()) :: boolean()
|
||||
def is_public?(%Object{data: %{"type" => "Tombstone"}}), do: false
|
||||
def is_public?(%Object{data: data}), do: is_public?(data)
|
||||
def is_public?(%Activity{data: %{"type" => "Move"}}), do: true
|
||||
def is_public?(%Activity{data: data}), do: is_public?(data)
|
||||
def is_public?(%{"directMessage" => true}), do: false
|
||||
@spec public?(Object.t() | Activity.t() | map()) :: boolean()
|
||||
def public?(%Object{data: %{"type" => "Tombstone"}}), do: false
|
||||
def public?(%Object{data: data}), do: public?(data)
|
||||
def public?(%Activity{data: %{"type" => "Move"}}), do: true
|
||||
def public?(%Activity{data: data}), do: public?(data)
|
||||
def public?(%{"directMessage" => true}), do: false
|
||||
|
||||
def is_public?(data) do
|
||||
def public?(data) do
|
||||
Utils.label_in_message?(Pleroma.Constants.as_public(), data) or
|
||||
Utils.label_in_message?(Utils.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 local_public?(%Object{data: data}), do: local_public?(data)
|
||||
def local_public?(%Activity{data: data}), do: local_public?(data)
|
||||
|
||||
def is_local_public?(data) do
|
||||
def local_public?(data) do
|
||||
Utils.label_in_message?(Utils.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),
|
||||
def private?(activity) do
|
||||
with false <- public?(activity),
|
||||
%User{follower_address: follower_address} <-
|
||||
User.get_cached_by_ap_id(activity.data["actor"]) do
|
||||
follower_address in activity.data["to"]
|
||||
@ -41,20 +41,20 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
|
||||
end
|
||||
end
|
||||
|
||||
def is_announceable?(activity, user, public \\ true) do
|
||||
is_public?(activity) ||
|
||||
(!public && is_private?(activity) && activity.data["actor"] == user.ap_id)
|
||||
def announceable?(activity, user, public \\ true) do
|
||||
public?(activity) ||
|
||||
(!public && private?(activity) && activity.data["actor"] == user.ap_id)
|
||||
end
|
||||
|
||||
def is_direct?(%Activity{data: %{"directMessage" => true}}), do: true
|
||||
def is_direct?(%Object{data: %{"directMessage" => true}}), do: true
|
||||
def direct?(%Activity{data: %{"directMessage" => true}}), do: true
|
||||
def direct?(%Object{data: %{"directMessage" => true}}), do: true
|
||||
|
||||
def is_direct?(activity) do
|
||||
!is_public?(activity) && !is_private?(activity)
|
||||
def direct?(activity) do
|
||||
!public?(activity) && !private?(activity)
|
||||
end
|
||||
|
||||
def is_list?(%{data: %{"listMessage" => _}}), do: true
|
||||
def is_list?(_), do: false
|
||||
def list?(%{data: %{"listMessage" => _}}), do: true
|
||||
def list?(_), do: false
|
||||
|
||||
@spec visible_for_user?(Object.t() | Activity.t() | nil, User.t() | nil) :: boolean()
|
||||
def visible_for_user?(%Object{data: %{"type" => "Tombstone"}}, _), do: false
|
||||
@ -77,7 +77,7 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
|
||||
when module in [Activity, Object] do
|
||||
if restrict_unauthenticated_access?(message),
|
||||
do: false,
|
||||
else: is_public?(message) and not is_local_public?(message)
|
||||
else: public?(message) and not local_public?(message)
|
||||
end
|
||||
|
||||
def visible_for_user?(%{__struct__: module} = message, user)
|
||||
@ -86,8 +86,8 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
|
||||
y = [message.data["actor"]] ++ message.data["to"] ++ (message.data["cc"] || [])
|
||||
|
||||
user_is_local = user.local
|
||||
federatable = not is_local_public?(message)
|
||||
(is_public?(message) || Enum.any?(x, &(&1 in y))) and (user_is_local || federatable)
|
||||
federatable = not local_public?(message)
|
||||
(public?(message) || Enum.any?(x, &(&1 in y))) and (user_is_local || federatable)
|
||||
end
|
||||
|
||||
def entire_thread_visible_for_user?(%Activity{} = activity, %User{} = user) do
|
||||
|
@ -372,7 +372,7 @@ defmodule Pleroma.Web.CommonAPI do
|
||||
do: visibility in ~w(public unlisted)
|
||||
|
||||
def public_announce?(object, _) do
|
||||
Visibility.is_public?(object)
|
||||
Visibility.public?(object)
|
||||
end
|
||||
|
||||
def get_visibility(_, _, %Participation{}), do: {"direct", "direct"}
|
||||
@ -500,7 +500,7 @@ defmodule Pleroma.Web.CommonAPI do
|
||||
end
|
||||
|
||||
defp activity_is_public(activity) do
|
||||
with false <- Visibility.is_public?(activity) do
|
||||
with false <- Visibility.public?(activity) do
|
||||
{:error, :visibility_error}
|
||||
end
|
||||
end
|
||||
|
@ -109,7 +109,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||
|
||||
def get_to_and_cc(%{visibility: "direct"} = draft) do
|
||||
# If the OP is a DM already, add the implicit actor.
|
||||
if draft.in_reply_to && Visibility.is_direct?(draft.in_reply_to) do
|
||||
if draft.in_reply_to && Visibility.direct?(draft.in_reply_to) do
|
||||
{Enum.uniq([draft.in_reply_to.data["actor"] | draft.mentions]), []}
|
||||
else
|
||||
{draft.mentions, []}
|
||||
|
@ -16,7 +16,7 @@ defmodule Pleroma.Web.EmbedController do
|
||||
def show(conn, %{"id" => id}) do
|
||||
with %Activity{local: true} = activity <-
|
||||
Activity.get_by_id_with_object(id),
|
||||
true <- Visibility.is_public?(activity.object) do
|
||||
true <- Visibility.public?(activity.object) do
|
||||
{:ok, author} = User.get_or_fetch(activity.object.data["actor"])
|
||||
|
||||
conn
|
||||
|
@ -85,12 +85,12 @@ defmodule Pleroma.Web.Gettext do
|
||||
Process.get({Pleroma.Web.Gettext, :locales}, [])
|
||||
end
|
||||
|
||||
def is_locale_list(locales) do
|
||||
def locale_list?(locales) do
|
||||
Enum.all?(locales, &is_binary/1)
|
||||
end
|
||||
|
||||
def put_locales(locales) do
|
||||
if is_locale_list(locales) do
|
||||
if locale_list?(locales) do
|
||||
Process.put({Pleroma.Web.Gettext, :locales}, Enum.uniq(locales))
|
||||
Gettext.put_locale(Enum.at(locales, 0, Gettext.get_locale()))
|
||||
:ok
|
||||
|
@ -214,7 +214,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||
do: user.follower_count,
|
||||
else: 0
|
||||
|
||||
bot = is_bot?(user)
|
||||
bot = bot?(user)
|
||||
|
||||
emojis =
|
||||
Enum.map(user.emoji, fn {shortcode, raw_url} ->
|
||||
@ -471,7 +471,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||
defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
|
||||
defp image_url(_), do: nil
|
||||
|
||||
defp is_bot?(user) do
|
||||
defp bot?(user) do
|
||||
# Because older and/or Mastodon clients may not recognize a Group actor properly,
|
||||
# and currently the group actor can only boost things, we should let these clients
|
||||
# think groups are bots.
|
||||
|
@ -138,9 +138,9 @@ defmodule Pleroma.Web.OAuth.Token do
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
def is_expired?(%__MODULE__{valid_until: valid_until}) do
|
||||
def expired?(%__MODULE__{valid_until: valid_until}) do
|
||||
NaiveDateTime.diff(NaiveDateTime.utc_now(), valid_until) > 0
|
||||
end
|
||||
|
||||
def is_expired?(_), do: false
|
||||
def expired?(_), do: false
|
||||
end
|
||||
|
@ -37,7 +37,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|
||||
with id <- Endpoint.url() <> conn.request_path,
|
||||
{_, %Activity{} = activity} <-
|
||||
{:activity, Activity.get_create_by_object_ap_id_with_object(id)},
|
||||
{_, true} <- {:public?, Visibility.is_public?(activity)} do
|
||||
{_, true} <- {:public?, Visibility.public?(activity)} do
|
||||
redirect(conn, to: "/notice/#{activity.id}")
|
||||
else
|
||||
reason when reason in [{:public?, false}, {:activity, nil}] ->
|
||||
@ -56,7 +56,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|
||||
def activity(conn, _params) do
|
||||
with id <- Endpoint.url() <> conn.request_path,
|
||||
{_, %Activity{} = activity} <- {:activity, Activity.normalize(id)},
|
||||
{_, true} <- {:public?, Visibility.is_public?(activity)} do
|
||||
{_, true} <- {:public?, Visibility.public?(activity)} do
|
||||
redirect(conn, to: "/notice/#{activity.id}")
|
||||
else
|
||||
reason when reason in [{:public?, false}, {:activity, nil}] ->
|
||||
@ -69,7 +69,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|
||||
|
||||
def notice(%{assigns: %{format: format}} = conn, %{"id" => id}) do
|
||||
with {_, %Activity{} = activity} <- {:activity, Activity.get_by_id_with_object(id)},
|
||||
{_, true} <- {:public?, Visibility.is_public?(activity)},
|
||||
{_, true} <- {:public?, Visibility.public?(activity)},
|
||||
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
||||
cond do
|
||||
format in ["json", "activity+json"] ->
|
||||
@ -106,7 +106,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
|
||||
# Returns an HTML embedded <audio> or <video> player suitable for embed iframes.
|
||||
def notice_player(conn, %{"id" => id}) do
|
||||
with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id_with_object(id),
|
||||
true <- Visibility.is_public?(activity),
|
||||
true <- Visibility.public?(activity),
|
||||
{_, true} <- {:visible?, Visibility.visible_for_user?(activity, _reading_user = nil)},
|
||||
%Object{} = object <- Object.normalize(activity, fetch: false),
|
||||
%{data: %{"attachment" => [%{"url" => [url | _]} | _]}} <- object,
|
||||
|
@ -23,14 +23,14 @@ defmodule Pleroma.Web.Plugs.OAuthPlug do
|
||||
def call(conn, _) do
|
||||
with {:ok, token_str} <- fetch_token_str(conn) do
|
||||
with {:ok, user, user_token} <- fetch_user_and_token(token_str),
|
||||
false <- Token.is_expired?(user_token) do
|
||||
false <- Token.expired?(user_token) do
|
||||
conn
|
||||
|> assign(:token, user_token)
|
||||
|> assign(:user, user)
|
||||
else
|
||||
_ ->
|
||||
with {:ok, app, app_token} <- fetch_app_and_token(token_str),
|
||||
false <- Token.is_expired?(app_token) do
|
||||
false <- Token.expired?(app_token) do
|
||||
conn
|
||||
|> assign(:token, app_token)
|
||||
|> assign(:app, app)
|
||||
|
@ -9,7 +9,7 @@ defmodule Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl do
|
||||
def ttl(data, _url) do
|
||||
image = Map.get(data, :image)
|
||||
|
||||
if is_aws_signed_url(image) do
|
||||
if aws_signed_url?(image) do
|
||||
image
|
||||
|> parse_query_params()
|
||||
|> format_query_params()
|
||||
@ -19,13 +19,13 @@ defmodule Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl do
|
||||
end
|
||||
end
|
||||
|
||||
defp is_aws_signed_url(image) when is_binary(image) and image != "" do
|
||||
defp aws_signed_url?(image) when is_binary(image) and image != "" do
|
||||
%URI{host: host, query: query} = URI.parse(image)
|
||||
|
||||
String.contains?(host, "amazonaws.com") and String.contains?(query, "X-Amz-Expires")
|
||||
end
|
||||
|
||||
defp is_aws_signed_url(_), do: nil
|
||||
defp aws_signed_url?(_), do: nil
|
||||
|
||||
defp parse_query_params(image) do
|
||||
%URI{query: query} = URI.parse(image)
|
||||
|
@ -22,7 +22,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
|
||||
def show(%{assigns: %{notice_id: notice_id}} = conn, _params) do
|
||||
with %Activity{local: true} = activity <-
|
||||
Activity.get_by_id_with_object(notice_id),
|
||||
true <- Visibility.is_public?(activity.object),
|
||||
true <- Visibility.public?(activity.object),
|
||||
{_, true} <- {:visible?, Visibility.visible_for_user?(activity, _reading_user = nil)},
|
||||
%User{} = user <- User.get_by_ap_id(activity.object.data["actor"]) do
|
||||
url = Helpers.url(conn) <> conn.request_path
|
||||
|
@ -245,7 +245,7 @@ defmodule Pleroma.Web.Streamer do
|
||||
defp do_stream("list", item) do
|
||||
# filter the recipient list if the activity is not public, see #270.
|
||||
recipient_lists =
|
||||
case Visibility.is_public?(item) do
|
||||
case Visibility.public?(item) do
|
||||
true ->
|
||||
Pleroma.List.get_lists_from_activity(item)
|
||||
|
||||
|
@ -29,7 +29,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowController do
|
||||
# GET /ostatus_subscribe
|
||||
#
|
||||
def follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do
|
||||
case is_status?(acct) do
|
||||
case status?(acct) do
|
||||
true -> follow_status(conn, user, acct)
|
||||
_ -> follow_account(conn, user, acct)
|
||||
end
|
||||
@ -57,7 +57,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowController do
|
||||
defp follow_template(%User{} = _user), do: "follow.html"
|
||||
defp follow_template(_), do: "follow_login.html"
|
||||
|
||||
defp is_status?(acct) do
|
||||
defp status?(acct) do
|
||||
case Fetcher.fetch_and_contain_remote_object_from_id(acct) do
|
||||
{:ok, %{"type" => type}} when type in @status_types ->
|
||||
true
|
||||
|
@ -6,26 +6,26 @@ defmodule Pleroma.EmojiTest do
|
||||
use ExUnit.Case, async: true
|
||||
alias Pleroma.Emoji
|
||||
|
||||
describe "is_unicode_emoji?/1" do
|
||||
describe "unicode?/1" do
|
||||
test "tells if a string is an unicode emoji" do
|
||||
refute Emoji.is_unicode_emoji?("X")
|
||||
refute Emoji.is_unicode_emoji?("ね")
|
||||
refute Emoji.unicode?("X")
|
||||
refute Emoji.unicode?("ね")
|
||||
|
||||
# Only accept fully-qualified (RGI) emoji
|
||||
# See http://www.unicode.org/reports/tr51/
|
||||
refute Emoji.is_unicode_emoji?("❤")
|
||||
refute Emoji.is_unicode_emoji?("☂")
|
||||
refute Emoji.unicode?("❤")
|
||||
refute Emoji.unicode?("☂")
|
||||
|
||||
assert Emoji.is_unicode_emoji?("🥺")
|
||||
assert Emoji.is_unicode_emoji?("🤰")
|
||||
assert Emoji.is_unicode_emoji?("❤️")
|
||||
assert Emoji.is_unicode_emoji?("🏳️⚧️")
|
||||
assert Emoji.is_unicode_emoji?("🫵")
|
||||
assert Emoji.unicode?("🥺")
|
||||
assert Emoji.unicode?("🤰")
|
||||
assert Emoji.unicode?("❤️")
|
||||
assert Emoji.unicode?("🏳️⚧️")
|
||||
assert Emoji.unicode?("🫵")
|
||||
|
||||
# Additionally, we accept regional indicators.
|
||||
assert Emoji.is_unicode_emoji?("🇵")
|
||||
assert Emoji.is_unicode_emoji?("🇴")
|
||||
assert Emoji.is_unicode_emoji?("🇬")
|
||||
assert Emoji.unicode?("🇵")
|
||||
assert Emoji.unicode?("🇴")
|
||||
assert Emoji.unicode?("🇬")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2424,20 +2424,20 @@ defmodule Pleroma.UserTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "is_internal_user?/1" do
|
||||
describe "internal?/1" do
|
||||
test "non-internal user returns false" do
|
||||
user = insert(:user)
|
||||
refute User.is_internal_user?(user)
|
||||
refute User.internal?(user)
|
||||
end
|
||||
|
||||
test "user with no nickname returns true" do
|
||||
user = insert(:user, %{nickname: nil})
|
||||
assert User.is_internal_user?(user)
|
||||
assert User.internal?(user)
|
||||
end
|
||||
|
||||
test "user with internal-prefixed nickname returns true" do
|
||||
user = insert(:user, %{nickname: "internal.test"})
|
||||
assert User.is_internal_user?(user)
|
||||
assert User.internal?(user)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -221,7 +221,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.local_public?(post)
|
||||
|
||||
object = Object.normalize(post, fetch: false)
|
||||
uuid = String.split(object.data["id"], "/") |> List.last()
|
||||
@ -238,7 +238,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.local_public?(post)
|
||||
|
||||
object = Object.normalize(post, fetch: false)
|
||||
uuid = String.split(object.data["id"], "/") |> List.last()
|
||||
@ -259,7 +259,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||
{:ok, post} =
|
||||
CommonAPI.post(user, %{status: "test @#{reader.nickname}", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.local_public?(post)
|
||||
|
||||
object = Object.normalize(post, fetch: false)
|
||||
uuid = String.split(object.data["id"], "/") |> List.last()
|
||||
@ -436,7 +436,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.local_public?(post)
|
||||
|
||||
uuid = String.split(post.data["id"], "/") |> List.last()
|
||||
|
||||
@ -452,7 +452,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{status: "test", visibility: "local"})
|
||||
|
||||
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||
assert Pleroma.Web.ActivityPub.Visibility.local_public?(post)
|
||||
|
||||
uuid = String.split(post.data["id"], "/") |> List.last()
|
||||
|
||||
|
@ -52,60 +52,60 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
||||
}
|
||||
end
|
||||
|
||||
test "is_direct?", %{
|
||||
test "direct?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
assert Visibility.is_direct?(direct)
|
||||
refute Visibility.is_direct?(public)
|
||||
refute Visibility.is_direct?(private)
|
||||
refute Visibility.is_direct?(unlisted)
|
||||
assert Visibility.is_direct?(list)
|
||||
assert Visibility.direct?(direct)
|
||||
refute Visibility.direct?(public)
|
||||
refute Visibility.direct?(private)
|
||||
refute Visibility.direct?(unlisted)
|
||||
assert Visibility.direct?(list)
|
||||
end
|
||||
|
||||
test "is_public?", %{
|
||||
test "public?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
refute Visibility.is_public?(direct)
|
||||
assert Visibility.is_public?(public)
|
||||
refute Visibility.is_public?(private)
|
||||
assert Visibility.is_public?(unlisted)
|
||||
refute Visibility.is_public?(list)
|
||||
refute Visibility.public?(direct)
|
||||
assert Visibility.public?(public)
|
||||
refute Visibility.public?(private)
|
||||
assert Visibility.public?(unlisted)
|
||||
refute Visibility.public?(list)
|
||||
end
|
||||
|
||||
test "is_private?", %{
|
||||
test "private?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
refute Visibility.is_private?(direct)
|
||||
refute Visibility.is_private?(public)
|
||||
assert Visibility.is_private?(private)
|
||||
refute Visibility.is_private?(unlisted)
|
||||
refute Visibility.is_private?(list)
|
||||
refute Visibility.private?(direct)
|
||||
refute Visibility.private?(public)
|
||||
assert Visibility.private?(private)
|
||||
refute Visibility.private?(unlisted)
|
||||
refute Visibility.private?(list)
|
||||
end
|
||||
|
||||
test "is_list?", %{
|
||||
test "list?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
refute Visibility.is_list?(direct)
|
||||
refute Visibility.is_list?(public)
|
||||
refute Visibility.is_list?(private)
|
||||
refute Visibility.is_list?(unlisted)
|
||||
assert Visibility.is_list?(list)
|
||||
refute Visibility.list?(direct)
|
||||
refute Visibility.list?(public)
|
||||
refute Visibility.list?(private)
|
||||
refute Visibility.list?(unlisted)
|
||||
assert Visibility.list?(list)
|
||||
end
|
||||
|
||||
test "visible_for_user? Activity", %{
|
||||
@ -227,7 +227,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
||||
} do
|
||||
Repo.delete(user)
|
||||
Pleroma.User.invalidate_cache(user)
|
||||
refute Visibility.is_private?(direct)
|
||||
refute Visibility.private?(direct)
|
||||
end
|
||||
|
||||
test "get_visibility", %{
|
||||
|
@ -506,7 +506,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
{:ok, convo_reply} =
|
||||
CommonAPI.post(user, %{status: ".", in_reply_to_conversation_id: participation.id})
|
||||
|
||||
assert Visibility.is_direct?(convo_reply)
|
||||
assert Visibility.direct?(convo_reply)
|
||||
|
||||
assert activity.data["context"] == convo_reply.data["context"]
|
||||
end
|
||||
@ -924,7 +924,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
|
||||
|
||||
{:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, user)
|
||||
assert Visibility.is_public?(announce_activity)
|
||||
assert Visibility.public?(announce_activity)
|
||||
end
|
||||
|
||||
test "can't repeat a repeat" do
|
||||
@ -946,7 +946,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
{:ok, %Activity{} = announce_activity} =
|
||||
CommonAPI.repeat(activity.id, user, %{visibility: "private"})
|
||||
|
||||
assert Visibility.is_private?(announce_activity)
|
||||
assert Visibility.private?(announce_activity)
|
||||
refute Visibility.visible_for_user?(announce_activity, nil)
|
||||
end
|
||||
|
||||
@ -959,7 +959,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
|
||||
{:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, author)
|
||||
|
||||
assert Visibility.is_private?(announce_activity)
|
||||
assert Visibility.private?(announce_activity)
|
||||
refute Visibility.visible_for_user?(announce_activity, nil)
|
||||
|
||||
assert Visibility.visible_for_user?(activity, follower)
|
||||
@ -1604,7 +1604,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
assert_not_called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
@ -1619,7 +1619,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
assert {:ok, %Activity{data: %{"deleted_activity_id" => ^activity_id}} = activity} =
|
||||
CommonAPI.delete(activity_id, user)
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
assert_not_called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
@ -1635,7 +1635,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
assert {:ok, %Activity{data: %{"type" => "Announce"}} = activity} =
|
||||
CommonAPI.repeat(activity_id, user)
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
@ -1653,7 +1653,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
assert {:ok, %Activity{data: %{"type" => "Undo"}} = activity} =
|
||||
CommonAPI.unrepeat(activity_id, user)
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
@ -1668,7 +1668,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
assert {:ok, %Activity{data: %{"type" => "Like"}} = activity} =
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
@ -1683,7 +1683,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
|
||||
with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do
|
||||
assert {:ok, activity} = CommonAPI.unfavorite(activity.id, user)
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
@ -1697,7 +1697,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
assert {:ok, %Activity{data: %{"type" => "EmojiReact"}} = activity} =
|
||||
CommonAPI.react_with_emoji(activity.id, user, "👍")
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
@ -1713,7 +1713,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||
assert {:ok, %Activity{data: %{"type" => "Undo"}} = activity} =
|
||||
CommonAPI.unreact_with_emoji(activity.id, user, "👍")
|
||||
|
||||
assert Visibility.is_local_public?(activity)
|
||||
assert Visibility.local_public?(activity)
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user