1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.NoEmptyPolicy do
6 @moduledoc "Filter local activities which have no content"
7 @behaviour Pleroma.Web.ActivityPub.MRF
12 def filter(%{"actor" => actor} = object) do
13 with true <- is_local?(actor),
14 true <- is_note?(object),
15 false <- has_attachment?(object),
16 true <- only_mentions?(object) do
17 {:reject, "[NoEmptyPolicy]"}
24 def filter(object), do: {:ok, object}
26 defp is_local?(actor) do
27 if actor |> String.starts_with?("#{Web.base_url()}") do
34 defp has_attachment?(%{
36 "object" => %{"type" => "Note", "attachment" => attachments}
38 when length(attachments) > 0,
41 defp has_attachment?(_), do: false
43 defp only_mentions?(%{"type" => "Create", "object" => %{"type" => "Note", "source" => source}}) do
45 source |> String.split() |> Enum.filter(&(not String.starts_with?(&1, "@"))) |> length
47 if non_mentions > 0 do
54 defp only_mentions?(_), do: false
56 defp is_note?(%{"type" => "Create", "object" => %{"type" => "Note"}}), do: true
57 defp is_note?(_), do: false
60 def describe, do: {:ok, %{}}