diff options
| author | Roger Braun <roger@rogerbraun.net> | 2017-11-03 08:51:17 +0100 | 
|---|---|---|
| committer | Roger Braun <roger@rogerbraun.net> | 2017-11-03 08:51:17 +0100 | 
| commit | c6b9b777dacef2fce51e43a25e3af9c9fac9a87e (patch) | |
| tree | 6cb29610bce67fc7cfb97d8414c8d85f12c63bbd | |
| parent | 5bf92e50be76b9dc2fa682b9f2ae252c0faad64e (diff) | |
| download | pleroma-c6b9b777dacef2fce51e43a25e3af9c9fac9a87e.tar.gz pleroma-c6b9b777dacef2fce51e43a25e3af9c9fac9a87e.zip | |
MastoAPI: Add list of blocked users.
| -rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 9 | ||||
| -rw-r--r-- | lib/pleroma/web/router.ex | 3 | ||||
| -rw-r--r-- | test/web/mastodon_api/mastodon_api_controller_test.exs | 14 | 
3 files changed, 25 insertions, 1 deletions
| diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 5e299c976..9c88cc4e8 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -335,6 +335,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do      end    end +  # TODO: Use proper query +  def blocks(%{assigns: %{user: user}} = conn, _) do +    with blocked_users <- user.info["blocks"] || [], +         accounts <- Enum.map(blocked_users, fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end) do +      res = AccountView.render("accounts.json", users: accounts, for: user, as: :user) +      json(conn, res) +    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 c4bbaa265..f96ec7213 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -65,7 +65,8 @@ defmodule Pleroma.Web.Router do      post "/follows", MastodonAPIController, :follow -    get "/blocks", MastodonAPIController, :empty_array +    get "/blocks", MastodonAPIController, :blocks +      get "/domain_blocks", MastodonAPIController, :empty_array      get "/follow_requests", MastodonAPIController, :empty_array      get "/mutes", MastodonAPIController, :empty_array diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index c91f96f38..d118026eb 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -309,6 +309,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do      assert %{"id" => id, "blocking" => false} = json_response(conn, 200)    end +  test "getting a list of blocks", %{conn: conn} do +    user = insert(:user) +    other_user = insert(:user) + +    {:ok, user} = User.block(user, other_user) + +    conn = conn +    |> assign(:user, user) +    |> get("/api/v1/blocks") + +    other_user_id = other_user.id +    assert [%{"id" => ^other_user_id}] = json_response(conn, 200) +  end +    test "unimplemented mute endpoints" do      user = insert(:user)      other_user = insert(:user) | 
