make 2fa UI less awful
[akkoma] / lib / pleroma / web / views / embed_view.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.EmbedView do
6 use Pleroma.Web, :view
7
8 alias Calendar.Strftime
9 alias Pleroma.Activity
10 alias Pleroma.Emoji.Formatter
11 alias Pleroma.Object
12 alias Pleroma.User
13 alias Pleroma.Web.Gettext
14 alias Pleroma.Web.MediaProxy
15 alias Pleroma.Web.Metadata.Utils
16 alias Pleroma.Web.Router.Helpers
17
18 use Phoenix.HTML
19
20 defdelegate full_nickname(user), to: User
21
22 @media_types ["image", "audio", "video"]
23
24 defp fetch_media_type(%{"mediaType" => mediaType}) do
25 Utils.fetch_media_type(@media_types, mediaType)
26 end
27
28 defp open_content? do
29 Pleroma.Config.get(
30 [:frontend_configurations, :collapse_message_with_subjects],
31 true
32 )
33 end
34
35 defp status_title(%Activity{object: %Object{data: %{"name" => name}}}) when is_binary(name),
36 do: name
37
38 defp status_title(%Activity{object: %Object{data: %{"summary" => summary}}})
39 when is_binary(summary),
40 do: summary
41
42 defp status_title(_), do: nil
43
44 defp activity_content(%Activity{object: %Object{data: %{"content" => content}}}) do
45 content |> Pleroma.HTML.filter_tags() |> raw()
46 end
47
48 defp activity_content(_), do: nil
49
50 defp activity_url(%User{local: true}, activity) do
51 Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
52 end
53
54 defp activity_url(%User{local: false}, %Activity{object: %Object{data: data}}) do
55 data["url"] || data["external_url"] || data["id"]
56 end
57
58 defp attachments(%Activity{object: %Object{data: %{"attachment" => attachments}}}) do
59 attachments
60 end
61
62 defp sensitive?(%Activity{object: %Object{data: %{"sensitive" => sensitive}}}) do
63 sensitive
64 end
65
66 defp published(%Activity{object: %Object{data: %{"published" => published}}}) do
67 published
68 |> NaiveDateTime.from_iso8601!()
69 |> Strftime.strftime!("%B %d, %Y, %l:%M %p")
70 end
71 end