Merge remote-tracking branch 'upstream/develop' into simplepolicy-announce-leak
[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_tags(params) do
9 providers = [
10 Pleroma.Web.Metadata.Providers.RelMe,
11 Pleroma.Web.Metadata.Providers.RestrictIndexing
12 | activated_providers()
13 ]
14
15 Enum.reduce(providers, "", fn parser, acc ->
16 rendered_html =
17 params
18 |> parser.build_tags()
19 |> Enum.map(&to_tag/1)
20 |> Enum.map(&HTML.safe_to_string/1)
21 |> Enum.join()
22
23 acc <> rendered_html
24 end)
25 end
26
27 def to_tag(data) do
28 with {name, attrs, _content = []} <- data do
29 HTML.Tag.tag(name, attrs)
30 else
31 {name, attrs, content} ->
32 HTML.Tag.content_tag(name, content, attrs)
33
34 _ ->
35 raise ArgumentError, message: "make_tag invalid args"
36 end
37 end
38
39 def activity_nsfw?(%{data: %{"sensitive" => sensitive}}) do
40 Pleroma.Config.get([__MODULE__, :unfurl_nsfw], false) == false and sensitive
41 end
42
43 def activity_nsfw?(_) do
44 false
45 end
46
47 defp activated_providers do
48 unless Pleroma.Config.restrict_unauthenticated_access?(:activities, :local) do
49 [Pleroma.Web.Metadata.Providers.Feed | Pleroma.Config.get([__MODULE__, :providers], [])]
50 else
51 []
52 end
53 end
54 end