masto_fe_view.ex 2.65 KB
Newer Older
minibikini's avatar
minibikini committed
1
# Pleroma: A lightweight social networking server
Haelwenn's avatar
Haelwenn committed
2
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
minibikini's avatar
minibikini committed
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
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.MastoFEView do
  use Pleroma.Web, :view
  alias Pleroma.Config
  alias Pleroma.User
  alias Pleroma.Web.MastodonAPI.AccountView
  alias Pleroma.Web.MastodonAPI.CustomEmojiView

  def initial_state(token, user, custom_emojis) do
    limit = Config.get([:instance, :limit])

    %{
      meta: %{
        streaming_api_base_url: Pleroma.Web.Endpoint.websocket_url(),
        access_token: token,
        locale: "en",
        domain: Pleroma.Web.Endpoint.host(),
        admin: "1",
        me: "#{user.id}",
        unfollow_modal: false,
        boost_modal: false,
        delete_modal: true,
        auto_play_gif: false,
        display_sensitive_media: false,
        reduce_motion: false,
        max_toot_chars: limit,
        mascot: User.get_mascot(user)["url"]
      },
      poll_limits: Config.get([:instance, :poll_limits]),
      rights: %{
34
35
        delete_others_notice: present?(user.is_moderator),
        admin: present?(user.is_admin)
minibikini's avatar
minibikini committed
36
37
38
      },
      compose: %{
        me: "#{user.id}",
39
        default_privacy: user.default_scope,
minibikini's avatar
minibikini committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
        default_sensitive: false,
        allow_content_types: Config.get([:instance, :allowed_post_formats])
      },
      media_attachments: %{
        accept_content_types: [
          ".jpg",
          ".jpeg",
          ".png",
          ".gif",
          ".webm",
          ".mp4",
          ".m4v",
          "image\/jpeg",
          "image\/png",
          "image\/gif",
          "video\/webm",
          "video\/mp4"
        ]
      },
59
      settings: user.mastofe_settings || %{},
minibikini's avatar
minibikini committed
60
61
62
63
64
65
66
67
68
69
70
71
      push_subscription: nil,
      accounts: %{user.id => render(AccountView, "show.json", user: user, for: user)},
      custom_emojis: render(CustomEmojiView, "index.json", custom_emojis: custom_emojis),
      char_limit: limit
    }
    |> Jason.encode!()
    |> Phoenix.HTML.raw()
  end

  defp present?(nil), do: false
  defp present?(false), do: false
  defp present?(_), do: true
KokaKiwi's avatar
KokaKiwi committed
72
73
74
75
76
77
78
79
80

  def render("manifest.json", _params) do
    %{
      name: Config.get([:instance, :name]),
      description: Config.get([:instance, :description]),
      icons: Config.get([:manifest, :icons]),
      theme_color: Config.get([:manifest, :theme_color]),
      background_color: Config.get([:manifest, :background_color]),
      display: "standalone",
81
      scope: Pleroma.Web.Endpoint.url(),
82
      start_url: Routes.masto_fe_path(Pleroma.Web.Endpoint, :index, ["getting-started"]),
KokaKiwi's avatar
KokaKiwi committed
83
84
85
86
87
88
89
90
      categories: [
        "social"
      ],
      serviceworker: %{
        src: "/sw.js"
      }
    }
  end
minibikini's avatar
minibikini committed
91
end