51 lines
1.8 KiB
Diff
51 lines
1.8 KiB
Diff
diff --git a/lib/pleroma/web/activity_pub/mrf/require_image_description.ex b/lib/pleroma/web/activity_pub/mrf/require_image_description.ex
|
|
new file mode 100644
|
|
index 000000000..67390e613
|
|
--- /dev/null
|
|
+++ b/lib/pleroma/web/activity_pub/mrf/require_image_description.ex
|
|
@@ -0,0 +1,45 @@
|
|
+defmodule Pleroma.Web.ActivityPub.MRF.RequireImageDescription do
|
|
+ @moduledoc "MRF policy which removes media without image description"
|
|
+ @behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
|
+
|
|
+ def is_valid_attachment(
|
|
+ %{"name" => name} = _
|
|
+ ), do: is_binary(name) and !String.equivalent?(name, "")
|
|
+ def is_valid_attachment(_), do: false
|
|
+
|
|
+ def mark_sensitive(object) do
|
|
+ object |> Map.put("sensitive", true)
|
|
+ object
|
|
+ end
|
|
+
|
|
+ def correct_attachment(object) do
|
|
+ if is_valid_attachment(object) do
|
|
+ object
|
|
+ else
|
|
+ mark_sensitive(object)
|
|
+ end
|
|
+ end
|
|
+
|
|
+ @impl true
|
|
+ def filter(
|
|
+ %{"type" => "Create", "object" => %{"attachment" => attachments} = object } = message
|
|
+ ) when is_list(attachments) and length(attachments) > 0 do
|
|
+ if attachments |> Enum.all?(fn(attach) -> is_valid_attachment(attach) end) do
|
|
+ {:ok, message}
|
|
+ else
|
|
+ attachments = attachments |> Enum.map(fn v -> correct_attachment(v) end)
|
|
+ object = object |> Map.update("summary", "Missing media descriptions", fn v -> v <> "; Missing media descriptions" end)
|
|
+ |> Map.put("attachment", attachments)
|
|
+ message = message |> Map.put("object", object)
|
|
+ {:ok, message}
|
|
+ end
|
|
+ end
|
|
+
|
|
+ @impl true
|
|
+ def filter(message), do: {:ok, message}
|
|
+
|
|
+ @impl true
|
|
+ def describe do
|
|
+ {:ok, %{mrf_sample: %{content: "<br/><emph>This post contained media without content description. Offending media has been removed from this post.</emph>"}}}
|
|
+ end
|
|
+end
|