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.HashtagPolicy do
6 require Pleroma.Constants
12 Reject, TWKN-remove or Set-Sensitive messsages with specific hashtags (without the leading #)
14 Note: This MRF Policy is always enabled, if you want to disable it you have to set empty lists.
17 @behaviour Pleroma.Web.ActivityPub.MRF.Policy
19 defp check_reject(message, hashtags) do
20 if Enum.any?(Config.get([:mrf_hashtag, :reject]), fn match -> match in hashtags end) do
21 {:reject, "[HashtagPolicy] Matches with rejected keyword"}
27 defp check_ftl_removal(%{"to" => to} = message, hashtags) do
28 if Pleroma.Constants.as_public() in to and
29 Enum.any?(Config.get([:mrf_hashtag, :federated_timeline_removal]), fn match ->
32 to = List.delete(to, Pleroma.Constants.as_public())
33 cc = [Pleroma.Constants.as_public() | message["cc"] || []]
39 |> Kernel.put_in(["object", "to"], to)
40 |> Kernel.put_in(["object", "cc"], cc)
48 defp check_ftl_removal(message, _hashtags), do: {:ok, message}
50 defp check_sensitive(message, hashtags) do
51 if Enum.any?(Config.get([:mrf_hashtag, :sensitive]), fn match -> match in hashtags end) do
52 {:ok, Kernel.put_in(message, ["object", "sensitive"], true)}
59 def filter(%{"type" => "Create", "object" => object} = message) do
60 hashtags = Object.hashtags(%Object{data: object})
63 with {:ok, message} <- check_reject(message, hashtags),
64 {:ok, message} <- check_ftl_removal(message, hashtags),
65 {:ok, message} <- check_sensitive(message, hashtags) do
74 def filter(message), do: {:ok, message}
79 Config.get(:mrf_hashtag)
82 {:ok, %{mrf_hashtag: mrf_hashtag}}
86 def config_description do
89 related_policy: "Pleroma.Web.ActivityPub.MRF.HashtagPolicy",
91 description: @moduledoc,
95 type: {:list, :string},
96 description: "A list of hashtags which result in message being rejected.",
100 key: :federated_timeline_removal,
101 type: {:list, :string},
103 "A list of hashtags which result in message being removed from federated timelines (a.k.a unlisted).",
108 type: {:list, :string},
110 "A list of hashtags which result in message being set as sensitive (a.k.a NSFW/R-18)",
111 suggestions: ["nsfw", "r18"]