Fix MRF policies to also work with Update
[akkoma] / lib / pleroma / web / metadata.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Metadata do
6 alias Phoenix.HTML
7
8 def build_static_tags(params) do
9 providers = [
10 Pleroma.Web.Metadata.Providers.Theme
11 ]
12
13 Enum.reduce(providers, "", fn parser, acc ->
14 rendered_html =
15 params
16 |> parser.build_tags()
17 |> Enum.map(&to_tag/1)
18 |> Enum.map(&HTML.safe_to_string/1)
19 |> Enum.join()
20
21 acc <> rendered_html
22 end)
23 end
24
25 def build_tags(params) do
26 providers = [
27 Pleroma.Web.Metadata.Providers.RelMe,
28 Pleroma.Web.Metadata.Providers.RestrictIndexing,
29 Pleroma.Web.Metadata.Providers.Theme
30 | activated_providers()
31 ]
32
33 Enum.reduce(providers, "", fn parser, acc ->
34 rendered_html =
35 params
36 |> parser.build_tags()
37 |> Enum.map(&to_tag/1)
38 |> Enum.map(&HTML.safe_to_string/1)
39 |> Enum.join()
40
41 acc <> rendered_html
42 end)
43 end
44
45 def to_tag(data) do
46 with {name, attrs, _content = []} <- data do
47 HTML.Tag.tag(name, attrs)
48 else
49 {name, attrs, content} ->
50 HTML.Tag.content_tag(name, content, attrs)
51
52 _ ->
53 raise ArgumentError, message: "make_tag invalid args"
54 end
55 end
56
57 def activity_nsfw?(%{data: %{"sensitive" => sensitive}}) do
58 Pleroma.Config.get([__MODULE__, :unfurl_nsfw], false) == false and sensitive
59 end
60
61 def activity_nsfw?(_) do
62 false
63 end
64
65 defp activated_providers do
66 unless Pleroma.Config.restrict_unauthenticated_access?(:activities, :local) do
67 [Pleroma.Web.Metadata.Providers.Feed | Pleroma.Config.get([__MODULE__, :providers], [])]
68 else
69 []
70 end
71 end
72 end