aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlambda <pleromagit@rogerbraun.net>2017-10-29 18:16:09 +0000
committerlambda <pleromagit@rogerbraun.net>2017-10-29 18:16:09 +0000
commit9168497f8fc051a12bf320bda9c762b96da2f27d (patch)
tree2e6905c7c2a6c12186dfbf060c822cab02615711
parent353b66e4326c27aca4a81ee133b73454d5eb0853 (diff)
parent71f66bd4589faddc35137ed3197f685555b77aaf (diff)
downloadpleroma-9168497f8fc051a12bf320bda9c762b96da2f27d.tar.gz
Merge branch 'missing-mastodon-follow-endpoint' into 'develop'
Fix return type of /api/v1/follows See merge request pleroma/pleroma!3
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex38
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs3
2 files changed, 17 insertions, 24 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 5032c735d..971772810 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -269,8 +269,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
end
- def follow(%{assigns: %{user: follower}} = conn, params) do
- with {:ok, %User{} = followed} <- get_user(params),
+ def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
+ with %User{} = followed <- Repo.get(User, id),
{:ok, follower} <- User.follow(follower, followed),
{:ok, activity} <- ActivityPub.follow(follower, followed) do
render conn, AccountView, "relationship.json", %{user: follower, target: followed}
@@ -282,6 +282,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
end
+ def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
+ with %User{} = followed <- Repo.get_by(User, nickname: uri),
+ {:ok, follower} <- User.follow(follower, followed),
+ {:ok, activity} <- ActivityPub.follow(follower, followed) do
+ render conn, AccountView, "account.json", %{user: followed}
+ else
+ {:error, message} = err ->
+ conn
+ |> put_resp_content_type("application/json")
+ |> send_resp(403, Poison.encode!(%{"error" => message}))
+ end
+ end
+
# TODO: Clean up and unify
def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
with %User{} = followed <- Repo.get(User, id),
@@ -343,25 +356,4 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
Logger.debug("Unimplemented, returning an empty array")
json(conn, [])
end
-
- defp get_user(params) do
- case params do
- %{"uri" => uri} ->
- case target = Repo.get_by(User, nickname: uri) do
- nil ->
- {:error, "No user with such nickname"}
- _ ->
- {:ok, target}
- end
- %{"id" => id} ->
- case target = Repo.get(User, id) do
- nil ->
- {:error, "No user with such id"}
- _ ->
- {:ok, target}
- end
- _ ->
- {:error, "You need to specify uri or id"}
- end
- end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index af2351706..acdb08ac2 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -287,7 +287,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> assign(:user, user)
|> post("/api/v1/follows", %{"uri" => other_user.nickname})
- assert %{"id" => id, "following" => true} = json_response(conn, 200)
+ assert %{"id" => id} = json_response(conn, 200)
+ assert id == other_user.id
end
test "unimplemented block/mute endpoints" do