MastoAPI: Persist frontend timelines and settings.
authoreal <eal@waifu.club>
Sat, 7 Apr 2018 14:26:56 +0000 (17:26 +0300)
committereal <eal@waifu.club>
Sat, 7 Apr 2018 14:26:56 +0000 (17:26 +0300)
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/router.ex

index ccba4710a7fe99579af3482ccbdd354ec03d5062..f2a800673bb4dbc3a62b9eab5de2b3cbb3e64af5 100644 (file)
@@ -603,7 +603,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
               "video\/mp4"
             ]
           },
-          settings: %{
+          settings: Map.get(user.info, "settings") || %{
             onboarded: true,
             home: %{
               shows: %{
@@ -648,6 +648,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController 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})
index 5f27f3caaab30cb9f31140cc152cdf7632d63569..a33d03fc99714972033ec091afeb8b5a15c2b052 100644 (file)
@@ -120,6 +120,12 @@ defmodule Pleroma.Web.Router 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)