Merge branch 'feature/reports-groups-and-multiple-state-update' into 'develop'
[akkoma] / lib / pleroma / web / static_fe / static_fe_view.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.Web.StaticFE.StaticFEView do
6 use Pleroma.Web, :view
7
8 alias Calendar.Strftime
9 alias Pleroma.Emoji.Formatter
10 alias Pleroma.User
11 alias Pleroma.Web.Endpoint
12 alias Pleroma.Web.Gettext
13 alias Pleroma.Web.MediaProxy
14 alias Pleroma.Web.Metadata.Utils
15 alias Pleroma.Web.Router.Helpers
16
17 use Phoenix.HTML
18
19 @media_types ["image", "audio", "video"]
20
21 def emoji_for_user(%User{} = user) do
22 user.source_data
23 |> Map.get("tag", [])
24 |> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
25 |> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
26 {String.trim(name, ":"), url}
27 end)
28 end
29
30 def fetch_media_type(%{"mediaType" => mediaType}) do
31 Utils.fetch_media_type(@media_types, mediaType)
32 end
33
34 def format_date(date) do
35 {:ok, date, _} = DateTime.from_iso8601(date)
36 Strftime.strftime!(date, "%Y/%m/%d %l:%M:%S %p UTC")
37 end
38
39 def instance_name, do: Pleroma.Config.get([:instance, :name], "Pleroma")
40
41 def open_content? do
42 Pleroma.Config.get(
43 [:frontend_configurations, :collapse_message_with_subjects],
44 true
45 )
46 end
47 end