1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.QuoteToLinkTagPolicy do
6 @moduledoc "Force a Link tag for posts quoting another post. (may break outgoing federation of quote posts with older Pleroma versions)"
7 @behaviour Pleroma.Web.ActivityPub.MRF.Policy
9 alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
11 require Pleroma.Constants
13 @impl Pleroma.Web.ActivityPub.MRF.Policy
14 def filter(%{"object" => %{"quoteUrl" => _} = object} = activity) do
15 {:ok, Map.put(activity, "object", filter_object(object))}
18 @impl Pleroma.Web.ActivityPub.MRF.Policy
19 def filter(object), do: {:ok, object}
21 @impl Pleroma.Web.ActivityPub.MRF.Policy
22 def describe, do: {:ok, %{}}
24 @impl Pleroma.Web.ActivityPub.MRF.Policy
25 def history_awareness, do: :auto
27 defp filter_object(%{"quoteUrl" => quote_url} = object) do
28 tags = object["tag"] || []
30 if Enum.any?(tags, fn tag ->
31 CommonFixes.object_link_tag?(tag) and tag["href"] == quote_url
42 "mediaType" => Pleroma.Constants.activity_json_canonical_mime_type(),