Merge branch 'feature/reports' into 'develop'
[akkoma] / lib / pleroma / emails / admin_email.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.AdminEmail do
6 @moduledoc "Admin emails"
7
8 import Swoosh.Email
9
10 alias Pleroma.Web.Router.Helpers
11
12 defp instance_config, do: Pleroma.Config.get(:instance)
13 defp instance_name, do: instance_config()[:name]
14 defp instance_email, do: instance_config()[:email]
15
16 defp user_url(user) do
17 Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, user.nickname)
18 end
19
20 def report(to, reporter, account, statuses, comment) do
21 comment_html =
22 if comment do
23 "<p>Comment: #{comment}"
24 else
25 ""
26 end
27
28 statuses_html =
29 if length(statuses) > 0 do
30 statuses_list_html =
31 statuses
32 |> Enum.map(fn %{id: id} ->
33 status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, id)
34 "<li><a href=\"#{status_url}\">#{status_url}</li>"
35 end)
36 |> Enum.join("\n")
37
38 """
39 <p> Statuses:
40 <ul>
41 #{statuses_list_html}
42 </ul>
43 </p>
44 """
45 else
46 ""
47 end
48
49 html_body = """
50 <p>Reported by: <a href="#{user_url(reporter)}">#{reporter.nickname}</a></p>
51 <p>Reported Account: <a href="#{user_url(account)}">#{account.nickname}</a></p>
52 #{comment_html}
53 #{statuses_html}
54 """
55
56 new()
57 |> to({to.name, to.email})
58 |> from({instance_name(), instance_email()})
59 |> reply_to({reporter.name, reporter.email})
60 |> subject("#{instance_name()} Report")
61 |> html_body(html_body)
62 end
63 end