defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy do
@moduledoc "Filter local activities which have no content"
- @behaviour Pleroma.Web.ActivityPub.MRF
+ @behaviour Pleroma.Web.ActivityPub.MRF.Policy
- alias Pleroma.Web
+ alias Pleroma.Web.Endpoint
@impl true
def filter(%{"actor" => actor} = object) do
def filter(object), do: {:ok, object}
defp is_local?(actor) do
- if actor |> String.starts_with?("#{Web.base_url()}") do
+ if actor |> String.starts_with?("#{Endpoint.url()}") do
true
else
false
defp has_attachment?(_), do: false
- defp only_mentions?(%{"type" => "Create", "object" => %{"type" => "Note", "source" => source}}) do
+ defp only_mentions?(%{"type" => "Create", "object" => %{"type" => "Note", "source" => source}})
+ when is_binary(source) do
+ non_mentions =
+ source |> String.split() |> Enum.filter(&(not String.starts_with?(&1, "@"))) |> length
+
+ if non_mentions > 0 do
+ false
+ else
+ true
+ end
+ end
+
+ defp only_mentions?(%{
+ "type" => "Create",
+ "object" => %{"type" => "Note", "source" => %{"content" => source}}
+ })
+ when is_binary(source) do
non_mentions =
source |> String.split() |> Enum.filter(&(not String.starts_with?(&1, "@"))) |> length