mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-23 06:58:58 +00:00
Merge branch 'missing-mastodon-follow-endpoint' into 'develop'
Add missing mastodon follow endpoint. See merge request pleroma/pleroma!2
This commit is contained in:
commit
353b66e432
|
@ -269,11 +269,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||
end
|
||||
end
|
||||
|
||||
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
|
||||
def follow(%{assigns: %{user: follower}} = conn, params) do
|
||||
with {:ok, %User{} = followed} <- get_user(params),
|
||||
{:ok, follower} <- User.follow(follower, followed),
|
||||
{:ok, activity} <- ActivityPub.follow(follower, followed) do
|
||||
render conn, AccountView, "relationship.json", %{user: follower, target: followed}
|
||||
else
|
||||
{:error, message} = err ->
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|> send_resp(403, Poison.encode!(%{"error" => message}))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -338,4 +343,25 @@ 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
|
||||
|
|
|
@ -62,6 +62,8 @@ defmodule Pleroma.Web.Router do
|
|||
post "/accounts/:id/mute", MastodonAPIController, :relationship_noop
|
||||
post "/accounts/:id/unmute", MastodonAPIController, :relationship_noop
|
||||
|
||||
post "/follows", MastodonAPIController, :follow
|
||||
|
||||
get "/blocks", MastodonAPIController, :empty_array
|
||||
get "/domain_blocks", MastodonAPIController, :empty_array
|
||||
get "/follow_requests", MastodonAPIController, :empty_array
|
||||
|
|
|
@ -281,6 +281,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> post("/api/v1/accounts/#{other_user.id}/unfollow")
|
||||
|
||||
assert %{"id" => id, "following" => false} = json_response(conn, 200)
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
conn = build_conn()
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/follows", %{"uri" => other_user.nickname})
|
||||
|
||||
assert %{"id" => id, "following" => true} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "unimplemented block/mute endpoints" do
|
||||
|
|
Loading…
Reference in a new issue