summaryrefslogtreecommitdiff
path: root/lib/pleroma/web/views/embed_view.ex
blob: 81e19673038d46e052378512ffcc71895dd5dd77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.EmbedView do
  use Pleroma.Web, :view

  alias Calendar.Strftime
  alias Pleroma.Activity
  alias Pleroma.Emoji.Formatter
  alias Pleroma.Object
  alias Pleroma.User
  alias Pleroma.Web.Gettext
  alias Pleroma.Web.MediaProxy
  alias Pleroma.Web.Metadata.Utils
  alias Pleroma.Web.Router.Helpers

  use Phoenix.HTML

  defdelegate full_nickname(user), to: User

  @media_types ["image", "audio", "video"]

  defp fetch_media_type(%{"mediaType" => mediaType}) do
    Utils.fetch_media_type(@media_types, mediaType)
  end

  defp open_content? do
    Pleroma.Config.get(
      [:frontend_configurations, :collapse_message_with_subjects],
      true
    )
  end

  defp status_title(%Activity{object: %Object{data: %{"name" => name}}}) when is_binary(name),
    do: name

  defp status_title(%Activity{object: %Object{data: %{"summary" => summary}}})
       when is_binary(summary),
       do: summary

  defp status_title(_), do: nil

  defp activity_content(%Activity{object: %Object{data: %{"content" => content}}}) do
    content |> Pleroma.HTML.filter_tags() |> raw()
  end

  defp activity_content(_), do: nil

  defp activity_url(%User{local: true}, activity) do
    Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
  end

  defp activity_url(%User{local: false}, %Activity{object: %Object{data: data}}) do
    data["url"] || data["external_url"] || data["id"]
  end

  defp attachments(%Activity{object: %Object{data: %{"attachment" => attachments}}}) do
    attachments
  end

  defp sensitive?(%Activity{object: %Object{data: %{"sensitive" => sensitive}}}) do
    sensitive
  end

  defp published(%Activity{object: %Object{data: %{"published" => published}}}) do
    published
    |> NaiveDateTime.from_iso8601!()
    |> Strftime.strftime!("%B %d, %Y, %l:%M %p")
  end
end