|
|
@ -293,7 +293,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|
|
|
|
|
|
|
|
|
|
|
@doc "POST /api/v1/accounts/:id/follow"
|
|
|
|
@doc "POST /api/v1/accounts/:id/follow"
|
|
|
|
def follow(%{assigns: %{user: %{id: id}, account: %{id: id}}}, _params) do
|
|
|
|
def follow(%{assigns: %{user: %{id: id}, account: %{id: id}}}, _params) do
|
|
|
|
{:error, :not_found}
|
|
|
|
{:error, "Can not follow yourself"}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def follow(%{assigns: %{user: follower, account: followed}} = conn, _params) do
|
|
|
|
def follow(%{assigns: %{user: follower, account: followed}} = conn, _params) do
|
|
|
@ -306,7 +306,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|
|
|
|
|
|
|
|
|
|
|
@doc "POST /api/v1/accounts/:id/unfollow"
|
|
|
|
@doc "POST /api/v1/accounts/:id/unfollow"
|
|
|
|
def unfollow(%{assigns: %{user: %{id: id}, account: %{id: id}}}, _params) do
|
|
|
|
def unfollow(%{assigns: %{user: %{id: id}, account: %{id: id}}}, _params) do
|
|
|
|
{:error, :not_found}
|
|
|
|
{:error, "Can not unfollow yourself"}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def unfollow(%{assigns: %{user: follower, account: followed}} = conn, _params) do
|
|
|
|
def unfollow(%{assigns: %{user: follower, account: followed}} = conn, _params) do
|
|
|
@ -356,14 +356,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@doc "POST /api/v1/follows"
|
|
|
|
@doc "POST /api/v1/follows"
|
|
|
|
def follows(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
|
|
|
|
def follows(conn, %{"uri" => uri}) do
|
|
|
|
with {_, %User{} = followed} <- {:followed, User.get_cached_by_nickname(uri)},
|
|
|
|
case User.get_cached_by_nickname(uri) do
|
|
|
|
{_, true} <- {:followed, follower.id != followed.id},
|
|
|
|
%User{} = user ->
|
|
|
|
{:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
|
|
|
|
conn
|
|
|
|
render(conn, "show.json", user: followed, for: follower)
|
|
|
|
|> assign(:account, user)
|
|
|
|
else
|
|
|
|
|> follow(%{})
|
|
|
|
{:followed, _} -> {:error, :not_found}
|
|
|
|
|
|
|
|
{:error, message} -> json_response(conn, :forbidden, %{error: message})
|
|
|
|
nil ->
|
|
|
|
|
|
|
|
{:error, :not_found}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|