1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.ForceMention do
6 require Pleroma.Constants
12 @behaviour Pleroma.Web.ActivityPub.MRF.Policy
14 defp get_author(url) do
15 with %Object{data: %{"actor" => actor}} <- Object.normalize(url, fetch: false),
16 %User{ap_id: ap_id, nickname: nickname} <- User.get_cached_by_ap_id(actor) do
17 %{"type" => "Mention", "href" => ap_id, "name" => "@#{nickname}"}
23 defp prepend_author(tags, _, false), do: tags
25 defp prepend_author(tags, nil, _), do: tags
27 defp prepend_author(tags, url, _) do
28 actor = get_author(url)
30 if not is_nil(actor) do
38 def filter(%{"type" => "Create", "object" => %{"tag" => tag} = object} = activity) do
43 Config.get([:mrf_force_mention, :mention_parent, true])
47 Config.get([:mrf_force_mention, :mention_quoted, true])
51 {:ok, put_in(activity["object"]["tag"], tag)}
55 def filter(object), do: {:ok, object}
58 def describe, do: {:ok, %{}}