Merge branch 'refactor/common_api' into 'develop'
[akkoma] / lib / pleroma / web / mastodon_api / controllers / mastodon_api_controller.ex
index 74a8b50556891408746fbc817a835f4749e4f0b9..e4ae632312a1da57d2312950d38d18c9b3afbbd0 100644 (file)
@@ -518,14 +518,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
     end
   end
 
-  def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do
-    params =
-      params
-      |> Map.put("in_reply_to_status_id", params["in_reply_to_id"])
-
-    scheduled_at = params["scheduled_at"]
-
-    if scheduled_at && ScheduledActivity.far_enough?(scheduled_at) do
+  def post_status(
+        %{assigns: %{user: user}} = conn,
+        %{"status" => _, "scheduled_at" => scheduled_at} = params
+      ) do
+    if ScheduledActivity.far_enough?(scheduled_at) do
       with {:ok, scheduled_activity} <-
              ScheduledActivity.create(user, %{"params" => params, "scheduled_at" => scheduled_at}) do
         conn
@@ -533,24 +530,26 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
         |> render("show.json", %{scheduled_activity: scheduled_activity})
       end
     else
-      params = Map.drop(params, ["scheduled_at"])
-
-      case CommonAPI.post(user, params) do
-        {:error, message} ->
-          conn
-          |> put_status(:unprocessable_entity)
-          |> json(%{error: message})
-
-        {:ok, activity} ->
-          conn
-          |> put_view(StatusView)
-          |> try_render("status.json", %{
-            activity: activity,
-            for: user,
-            as: :activity,
-            with_direct_conversation_id: true
-          })
-      end
+      post_status(conn, Map.drop(params, ["scheduled_at"]))
+    end
+  end
+
+  def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do
+    case CommonAPI.post(user, params) do
+      {:ok, activity} ->
+        conn
+        |> put_view(StatusView)
+        |> try_render("status.json", %{
+          activity: activity,
+          for: user,
+          as: :activity,
+          with_direct_conversation_id: true
+        })
+
+      {:error, message} ->
+        conn
+        |> put_status(:unprocessable_entity)
+        |> json(%{error: message})
     end
   end