aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/masto_fe_controller.ex36
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/auth_controller.ex2
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex124
-rw-r--r--lib/pleroma/web/mastodon_api/views/mastodon_view.ex8
-rw-r--r--lib/pleroma/web/router.ex14
-rw-r--r--lib/pleroma/web/templates/masto_fe/index.html.eex (renamed from lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex)2
-rw-r--r--lib/pleroma/web/views/masto_fe_view.ex102
7 files changed, 147 insertions, 141 deletions
diff --git a/lib/pleroma/web/masto_fe_controller.ex b/lib/pleroma/web/masto_fe_controller.ex
new file mode 100644
index 000000000..ac9af7502
--- /dev/null
+++ b/lib/pleroma/web/masto_fe_controller.ex
@@ -0,0 +1,36 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastoFEController do
+ use Pleroma.Web, :controller
+
+ alias Pleroma.User
+
+ @doc "GET /web/*path"
+ def index(%{assigns: %{user: user}} = conn, _params) do
+ token = get_session(conn, :oauth_token)
+
+ if user && token do
+ conn
+ |> put_layout(false)
+ |> render("index.html", token: token, user: user, custom_emojis: Pleroma.Emoji.get_all())
+ else
+ conn
+ |> put_session(:return_to, conn.request_path)
+ |> redirect(to: "/web/login")
+ end
+ end
+
+ @doc "PUT /api/web/settings"
+ def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
+ with {:ok, _} <- User.update_info(user, &User.Info.mastodon_settings_update(&1, settings)) do
+ json(conn, %{})
+ else
+ e ->
+ conn
+ |> put_status(:internal_server_error)
+ |> json(%{error: inspect(e)})
+ end
+ end
+end
diff --git a/lib/pleroma/web/mastodon_api/controllers/auth_controller.ex b/lib/pleroma/web/mastodon_api/controllers/auth_controller.ex
index 0dee670af..bfd5120ba 100644
--- a/lib/pleroma/web/mastodon_api/controllers/auth_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/auth_controller.ex
@@ -75,7 +75,7 @@ defmodule Pleroma.Web.MastodonAPI.AuthController do
defp local_mastodon_root_path(conn) do
case get_session(conn, :return_to) do
nil ->
- mastodon_api_path(conn, :index, ["getting-started"])
+ masto_fe_path(conn, :index, ["getting-started"])
return_to ->
delete_session(conn, :return_to)
diff --git a/lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex
index a66335c02..e92f5d089 100644
--- a/lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex
@@ -8,13 +8,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]
alias Pleroma.Bookmark
- alias Pleroma.Config
alias Pleroma.Pagination
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.MastodonAPI.AccountView
- alias Pleroma.Web.MastodonAPI.MastodonView
alias Pleroma.Web.MastodonAPI.StatusView
require Logger
@@ -87,124 +85,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> render("index.json", %{activities: activities, for: user, as: :activity})
end
- def index(%{assigns: %{user: user}} = conn, _params) do
- token = get_session(conn, :oauth_token)
-
- if user && token do
- mastodon_emoji =
- Pleroma.Web.MastodonAPI.CustomEmojiView.render("index.json", %{
- custom_emojis: Pleroma.Emoji.get_all()
- })
-
- limit = Config.get([:instance, :limit])
-
- accounts = Map.put(%{}, user.id, AccountView.render("show.json", %{user: user, for: user}))
-
- initial_state =
- %{
- 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: %{
- delete_others_notice: present?(user.info.is_moderator),
- admin: present?(user.info.is_admin)
- },
- compose: %{
- me: "#{user.id}",
- default_privacy: user.info.default_scope,
- 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"
- ]
- },
- settings:
- user.info.settings ||
- %{
- onboarded: true,
- home: %{
- shows: %{
- reblog: true,
- reply: true
- }
- },
- notifications: %{
- alerts: %{
- follow: true,
- favourite: true,
- reblog: true,
- mention: true
- },
- shows: %{
- follow: true,
- favourite: true,
- reblog: true,
- mention: true
- },
- sounds: %{
- follow: true,
- favourite: true,
- reblog: true,
- mention: true
- }
- }
- },
- push_subscription: nil,
- accounts: accounts,
- custom_emojis: mastodon_emoji,
- char_limit: limit
- }
- |> Jason.encode!()
-
- conn
- |> put_layout(false)
- |> put_view(MastodonView)
- |> render("index.html", %{initial_state: initial_state})
- else
- conn
- |> put_session(:return_to, conn.request_path)
- |> redirect(to: "/web/login")
- end
- end
-
- def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
- with {:ok, _} <- User.update_info(user, &User.Info.mastodon_settings_update(&1, settings)) do
- json(conn, %{})
- else
- e ->
- conn
- |> put_status(:internal_server_error)
- |> json(%{error: inspect(e)})
- end
- end
-
# Stubs for unimplemented mastodon api
#
def empty_array(conn, _) do
@@ -216,8 +96,4 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
Logger.debug("Unimplemented, returning an empty object")
json(conn, %{})
end
-
- defp present?(nil), do: false
- defp present?(false), do: false
- defp present?(_), do: true
end
diff --git a/lib/pleroma/web/mastodon_api/views/mastodon_view.ex b/lib/pleroma/web/mastodon_api/views/mastodon_view.ex
deleted file mode 100644
index 33b9a74be..000000000
--- a/lib/pleroma/web/mastodon_api/views/mastodon_view.ex
+++ /dev/null
@@ -1,8 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.MastodonAPI.MastodonView do
- use Pleroma.Web, :view
- import Phoenix.HTML
-end
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 5d14c7742..f91af8137 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -451,10 +451,10 @@ defmodule Pleroma.Web.Router do
end
end
- scope "/api/web", Pleroma.Web.MastodonAPI do
+ scope "/api/web", Pleroma.Web do
pipe_through([:authenticated_api, :oauth_write])
- put("/settings", MastodonAPIController, :put_settings)
+ put("/settings", MastoFEController, :put_settings)
end
scope "/api/v1", Pleroma.Web.MastodonAPI do
@@ -658,17 +658,17 @@ defmodule Pleroma.Web.Router do
get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
end
- scope "/", Pleroma.Web.MastodonAPI do
+ scope "/", Pleroma.Web do
pipe_through(:mastodon_html)
- get("/web/login", AuthController, :login)
- delete("/auth/sign_out", AuthController, :logout)
+ get("/web/login", MastodonAPI.AuthController, :login)
+ delete("/auth/sign_out", MastodonAPI.AuthController, :logout)
- post("/auth/password", AuthController, :password_reset)
+ post("/auth/password", MastodonAPI.AuthController, :password_reset)
scope [] do
pipe_through(:oauth_read)
- get("/web/*path", MastodonAPIController, :index)
+ get("/web/*path", MastoFEController, :index)
end
end
diff --git a/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex b/lib/pleroma/web/templates/masto_fe/index.html.eex
index 3325beca1..feff36fae 100644
--- a/lib/pleroma/web/templates/mastodon_api/mastodon/index.html.eex
+++ b/lib/pleroma/web/templates/masto_fe/index.html.eex
@@ -14,7 +14,7 @@
<link rel='preload' as='script' crossorigin='anonymous' href='/packs/features/compose.js'>
<link rel='preload' as='script' crossorigin='anonymous' href='/packs/features/home_timeline.js'>
<link rel='preload' as='script' crossorigin='anonymous' href='/packs/features/notifications.js'>
-<script id='initial-state' type='application/json'><%= raw @initial_state %></script>
+<script id='initial-state' type='application/json'><%= initial_state(@token, @user, @custom_emojis) %></script>
<script src="/packs/core/common.js"></script>
<link rel="stylesheet" media="all" href="/packs/core/common.css" />
diff --git a/lib/pleroma/web/views/masto_fe_view.ex b/lib/pleroma/web/views/masto_fe_view.ex
new file mode 100644
index 000000000..21b086d4c
--- /dev/null
+++ b/lib/pleroma/web/views/masto_fe_view.ex
@@ -0,0 +1,102 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# 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
+
+ @default_settings %{
+ onboarded: true,
+ home: %{
+ shows: %{
+ reblog: true,
+ reply: true
+ }
+ },
+ notifications: %{
+ alerts: %{
+ follow: true,
+ favourite: true,
+ reblog: true,
+ mention: true
+ },
+ shows: %{
+ follow: true,
+ favourite: true,
+ reblog: true,
+ mention: true
+ },
+ sounds: %{
+ follow: true,
+ favourite: true,
+ reblog: true,
+ mention: true
+ }
+ }
+ }
+
+ 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: %{
+ delete_others_notice: present?(user.info.is_moderator),
+ admin: present?(user.info.is_admin)
+ },
+ compose: %{
+ me: "#{user.id}",
+ default_privacy: user.info.default_scope,
+ 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"
+ ]
+ },
+ settings: user.info.settings || @default_settings,
+ 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
+end