logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

quote_to_link_tag_policy.ex (1447B)


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