2020-03-20 11:19:34 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-03-20 11:19:34 -06:00
|
|
|
# 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
|
|
|
|
|
2023-07-17 12:18:21 -06:00
|
|
|
import Phoenix.HTML
|
2020-03-20 11:19:34 -06:00
|
|
|
|
2021-01-28 09:49:43 -07:00
|
|
|
defdelegate full_nickname(user), to: User
|
|
|
|
|
2020-03-20 11:19:34 -06:00
|
|
|
@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
|
2023-08-15 04:22:18 -06:00
|
|
|
~p[/notice/#{activity}]
|
2020-03-20 11:19:34 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
defp activity_url(%User{local: false}, %Activity{object: %Object{data: data}}) do
|
|
|
|
data["url"] || data["external_url"] || data["id"]
|
|
|
|
end
|
|
|
|
|
2023-07-17 12:18:21 -06:00
|
|
|
defp attachments(%Activity{object: %Object{data: %{"attachment" => attachments}}})
|
|
|
|
when is_list(attachments) do
|
2020-03-20 11:19:34 -06:00
|
|
|
attachments
|
|
|
|
end
|
|
|
|
|
2023-07-17 12:18:21 -06:00
|
|
|
defp attachments(_), do: []
|
|
|
|
|
2020-03-20 11:19:34 -06:00
|
|
|
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
|