mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-27 08:16:16 +00:00
Add mastodon API endpoint for follow
This commit is contained in:
parent
5293516730
commit
813d2eaaf0
|
@ -269,11 +269,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
def follow(%{assigns: %{user: follower}} = conn, params) do
|
||||||
with %User{} = followed <- Repo.get(User, id),
|
with {:ok, %User{} = followed} <- get_user(params),
|
||||||
{:ok, follower} <- User.follow(follower, followed),
|
{:ok, follower} <- User.follow(follower, followed),
|
||||||
{:ok, activity} <- ActivityPub.follow(follower, followed) do
|
{:ok, activity} <- ActivityPub.follow(follower, followed) do
|
||||||
render conn, AccountView, "relationship.json", %{user: follower, target: followed}
|
render conn, AccountView, "relationship.json", %{user: follower, target: followed}
|
||||||
|
else
|
||||||
|
err -> err
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -338,4 +340,25 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
Logger.debug("Unimplemented, returning an empty array")
|
Logger.debug("Unimplemented, returning an empty array")
|
||||||
json(conn, [])
|
json(conn, [])
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -62,6 +62,8 @@ defmodule Pleroma.Web.Router do
|
||||||
post "/accounts/:id/mute", MastodonAPIController, :relationship_noop
|
post "/accounts/:id/mute", MastodonAPIController, :relationship_noop
|
||||||
post "/accounts/:id/unmute", MastodonAPIController, :relationship_noop
|
post "/accounts/:id/unmute", MastodonAPIController, :relationship_noop
|
||||||
|
|
||||||
|
post "/follows", MastodonAPIController, :follow
|
||||||
|
|
||||||
get "/blocks", MastodonAPIController, :empty_array
|
get "/blocks", MastodonAPIController, :empty_array
|
||||||
get "/domain_blocks", MastodonAPIController, :empty_array
|
get "/domain_blocks", MastodonAPIController, :empty_array
|
||||||
get "/follow_requests", MastodonAPIController, :empty_array
|
get "/follow_requests", MastodonAPIController, :empty_array
|
||||||
|
|
Loading…
Reference in a new issue