Extract opengraph/oembed into separate module
[akkoma] / lib / pleroma / web / mastodon_api / mastodon_api_controller.ex
index 57de92dc00eb06184f5a93a4259a8821693232b3..5c8602322f23310592f0aebcb4ac0e6a5ae7ac37 100644 (file)
@@ -437,10 +437,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   end
 
   # Instead of returning a 400 when no "id" params is present, Mastodon returns an empty array.
-  def relationships(%{assigns: %{user: user}} = conn, _) do
-    conn
-    |> json([])
-  end
+  def relationships(%{assigns: %{user: _user}} = conn, _), do: json(conn, [])
 
   def update_media(%{assigns: %{user: user}} = conn, data) do
     with %Object{} = object <- Repo.get(Object, data["id"]),
@@ -850,7 +847,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   end
 
   def list_timeline(%{assigns: %{user: user}} = conn, %{"list_id" => id} = params) do
-    with %Pleroma.List{title: title, following: following} <- Pleroma.List.get(id, user) do
+    with %Pleroma.List{title: _title, following: following} <- Pleroma.List.get(id, user) do
       params =
         params
         |> Map.put("type", "Create")
@@ -979,15 +976,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   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(%{})
+    info_cng = User.Info.mastodon_settings_update(user.info, settings)
+
+    with changeset <- User.update_changeset(user),
+         changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng),
+         {:ok, _user} <- User.update_and_set_cache(changeset) do
+      json(conn, %{})
     else
       e ->
-        conn
-        |> json(%{error: inspect(e)})
+        json(conn, %{error: inspect(e)})
     end
   end