aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2017-11-03 08:38:05 +0100
committerRoger Braun <roger@rogerbraun.net>2017-11-03 08:38:05 +0100
commit5bf92e50be76b9dc2fa682b9f2ae252c0faad64e (patch)
tree15a60a01858170c2a0d1b06aa4af81a34be8cacd /lib
parent33beb51da423f5f80311453ad9025aa66984eb12 (diff)
downloadpleroma-5bf92e50be76b9dc2fa682b9f2ae252c0faad64e.tar.gz
MastoAPI: Add blocking.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex24
-rw-r--r--lib/pleroma/web/router.ex4
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 881bd38df..5e299c976 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -311,6 +311,30 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
end
+ def block(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
+ with %User{} = blocked <- Repo.get(User, id),
+ {:ok, blocker} <- User.block(blocker, blocked) do
+ render conn, AccountView, "relationship.json", %{user: blocker, target: blocked}
+ else
+ {:error, message} = err ->
+ conn
+ |> put_resp_content_type("application/json")
+ |> send_resp(403, Poison.encode!(%{"error" => message}))
+ end
+ end
+
+ def unblock(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
+ with %User{} = blocked <- Repo.get(User, id),
+ {:ok, blocker} <- User.unblock(blocker, blocked) do
+ render conn, AccountView, "relationship.json", %{user: blocker, target: blocked}
+ else
+ {:error, message} = err ->
+ conn
+ |> put_resp_content_type("application/json")
+ |> send_resp(403, Poison.encode!(%{"error" => message}))
+ end
+ end
+
def search(%{assigns: %{user: user}} = conn, %{"q" => query} = params) do
accounts = User.search(query, params["resolve"] == "true")
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 1fb5eadf6..c4bbaa265 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -58,8 +58,8 @@ defmodule Pleroma.Web.Router do
get "/accounts/search", MastodonAPIController, :account_search
post "/accounts/:id/follow", MastodonAPIController, :follow
post "/accounts/:id/unfollow", MastodonAPIController, :unfollow
- post "/accounts/:id/block", MastodonAPIController, :relationship_noop
- post "/accounts/:id/unblock", MastodonAPIController, :relationship_noop
+ post "/accounts/:id/block", MastodonAPIController, :block
+ post "/accounts/:id/unblock", MastodonAPIController, :unblock
post "/accounts/:id/mute", MastodonAPIController, :relationship_noop
post "/accounts/:id/unmute", MastodonAPIController, :relationship_noop