AccountController: Extract blocking to CommonAPI.
authorlain <lain@soykaf.club>
Thu, 25 Jun 2020 09:44:04 +0000 (11:44 +0200)
committerlain <lain@soykaf.club>
Thu, 25 Jun 2020 09:44:04 +0000 (11:44 +0200)
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/mastodon_api/controllers/account_controller.ex

index 04e081a8e88def3de6bf6139ff3a08854d612699..fd714907953901aaf3f2dd814e0347909c9d4f76 100644 (file)
@@ -25,6 +25,13 @@ defmodule Pleroma.Web.CommonAPI do
   require Pleroma.Constants
   require Logger
 
+  def block(blocker, blocked) do
+    with {:ok, block_data, _} <- Builder.block(blocker, blocked),
+         {:ok, block, _} <- Pipeline.common_pipeline(block_data, local: true) do
+      {:ok, block}
+    end
+  end
+
   def post_chat_message(%User{} = user, %User{} = recipient, content, opts \\ []) do
     with maybe_attachment <- opts[:media_id] && Object.get_by_id(opts[:media_id]),
          :ok <- validate_chat_content_length(content, !!maybe_attachment),
index 7a88a847c412f2818eddb863f54df41ac95980b1..b5008d69b261daca246932809629bf0fe5bf821c 100644 (file)
@@ -385,8 +385,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
 
   @doc "POST /api/v1/accounts/:id/block"
   def block(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do
-    with {:ok, _user_block} <- User.block(blocker, blocked),
-         {:ok, _activity} <- ActivityPub.block(blocker, blocked) do
+    with {:ok, _activity} <- CommonAPI.block(blocker, blocked) do
       render(conn, "relationship.json", user: blocker, target: blocked)
     else
       {:error, message} -> json_response(conn, :forbidden, %{error: message})