Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[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 @media_types ["image", "audio", "video"]
21
22 defp fetch_media_type(%{"mediaType" => mediaType}) do
23 Utils.fetch_media_type(@media_types, mediaType)
24 end
25
26 defp open_content? do
27 Pleroma.Config.get(
28 [:frontend_configurations, :collapse_message_with_subjects],
29 true
30 )
31 end
32
33 defp full_nickname(user) do
34 %{host: host} = URI.parse(user.ap_id)
35 "@" <> user.nickname <> "@" <> host
36 end
37
38 defp status_title(%Activity{object: %Object{data: %{"name" => name}}}) when is_binary(name),
39 do: name
40
41 defp status_title(%Activity{object: %Object{data: %{"summary" => summary}}})
42 when is_binary(summary),
43 do: summary
44
45 defp status_title(_), do: nil
46
47 defp activity_content(%Activity{object: %Object{data: %{"content" => content}}}) do
48 content |> Pleroma.HTML.filter_tags() |> raw()
49 end
50
51 defp activity_content(_), do: nil
52
53 defp activity_url(%User{local: true}, activity) do
54 Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
55 end
56
57 defp activity_url(%User{local: false}, %Activity{object: %Object{data: data}}) do
58 data["url"] || data["external_url"] || data["id"]
59 end
60
61 defp attachments(%Activity{object: %Object{data: %{"attachment" => attachments}}}) do
62 attachments
63 end
64
65 defp sensitive?(%Activity{object: %Object{data: %{"sensitive" => sensitive}}}) do
66 sensitive
67 end
68
69 defp published(%Activity{object: %Object{data: %{"published" => published}}}) do
70 published
71 |> NaiveDateTime.from_iso8601!()
72 |> Strftime.strftime!("%B %d, %Y, %l:%M %p")
73 end
74 end