From 7c47534970e0a648ded4700fe20c99d6ab15cd5c Mon Sep 17 00:00:00 2001 From: eal Date: Sat, 7 Apr 2018 17:26:56 +0300 Subject: [PATCH] MastoAPI: Persist frontend timelines and settings. --- .../web/mastodon_api/mastodon_api_controller.ex | 14 +++++++++++++- lib/pleroma/web/router.ex | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index ccba4710a..f2a800673 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -603,7 +603,7 @@ def index(%{assigns: %{user: user}} = conn, _params) do "video\/mp4" ] }, - settings: %{ + settings: Map.get(user.info, "settings") || %{ onboarded: true, home: %{ shows: %{ @@ -648,6 +648,18 @@ def index(%{assigns: %{user: user}} = conn, _params) do end end + def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do + with new_info <- Map.put(user.info, "settings", settings), + change <- User.info_changeset(user, %{info: new_info}), + {:ok, _user} <- User.update_and_set_cache(change) do + conn + |> json(%{}) + else e -> + conn + |> json(%{error: inspect(e)}) + end + end + def login(conn, _) do conn |> render(MastodonView, "login.html", %{error: false}) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 5f27f3caa..a33d03fc9 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -120,6 +120,12 @@ def user_fetcher(username) do post("/media", MastodonAPIController, :upload) end + scope "/api/web", Pleroma.Web.MastodonAPI do + pipe_through(:authenticated_api) + + put("/settings", MastodonAPIController, :put_settings) + end + scope "/api/v1", Pleroma.Web.MastodonAPI do pipe_through(:api) get("/instance", MastodonAPIController, :masto_instance)