1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
7 @behaviour Pleroma.Web.ActivityPub.MRF
9 defp get_tags(%User{tags: tags}) when is_list(tags), do: tags
10 defp get_tags(_), do: []
13 "mrf_tag:media-force-nsfw",
14 %{"type" => "Create", "object" => %{"attachment" => child_attachment} = object} = message
16 when length(child_attachment) > 0 do
17 tags = (object["tag"] || []) ++ ["nsfw"]
21 |> Map.put("tags", tags)
22 |> Map.put("sensitive", true)
24 message = Map.put(message, "object", object)
30 "mrf_tag:media-strip",
31 %{"type" => "Create", "object" => %{"attachment" => child_attachment} = object} = message
33 when length(child_attachment) > 0 do
34 object = Map.delete(object, "attachment")
35 message = Map.put(message, "object", object)
41 "mrf_tag:force-unlisted",
42 %{"type" => "Create", "to" => to, "cc" => cc, "actor" => actor} = message
44 user = User.get_cached_by_ap_id(actor)
46 if Enum.member?(to, "https://www.w3.org/ns/activitystreams#Public") do
48 List.delete(to, "https://www.w3.org/ns/activitystreams#Public") ++ [user.follower_address]
51 List.delete(cc, user.follower_address) ++ ["https://www.w3.org/ns/activitystreams#Public"]
66 %{"type" => "Create", "to" => to, "cc" => cc, "actor" => actor} = message
68 user = User.get_cached_by_ap_id(actor)
70 if Enum.member?(to, "https://www.w3.org/ns/activitystreams#Public") or
71 Enum.member?(cc, "https://www.w3.org/ns/activitystreams#Public") do
73 List.delete(to, "https://www.w3.org/ns/activitystreams#Public") ++ [user.follower_address]
75 cc = List.delete(cc, "https://www.w3.org/ns/activitystreams#Public")
88 defp process_tag(_, message), do: {:ok, message}
91 def filter(%{"object" => target_actor, "type" => "Follow"} = message) do
92 User.get_cached_by_ap_id(target_actor)
94 |> Enum.reduce({:ok, message}, fn
95 tag, {:ok, message} ->
96 process_tag(tag, message)
104 def filter(%{"actor" => actor, "type" => "Create"} = message) do
105 User.get_cached_by_ap_id(actor)
107 |> Enum.reduce({:ok, message}, fn
108 tag, {:ok, message} ->
109 process_tag(tag, message)
117 def filter(message), do: {:ok, message}