Add an endpoint /api/v1/accounts/:id/lists to get lists to which account belongs
This commit is contained in:
parent
ad3181895c
commit
e8c698af41
|
@ -69,6 +69,17 @@ def get_lists_from_activity(%Activity{actor: ap_id}) do
|
||||||
Repo.all(query)
|
Repo.all(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Get lists to which the account belongs.
|
||||||
|
def get_lists_account_belongs(%User{} = owner, account_id) do
|
||||||
|
user = Repo.get(User, account_id)
|
||||||
|
query =
|
||||||
|
from(
|
||||||
|
l in Pleroma.List,
|
||||||
|
where: l.user_id == ^owner.id and fragment("? = ANY(?)", ^user.follower_address, l.following)
|
||||||
|
)
|
||||||
|
Repo.all(query)
|
||||||
|
end
|
||||||
|
|
||||||
def rename(%Pleroma.List{} = list, title) do
|
def rename(%Pleroma.List{} = list, title) do
|
||||||
list
|
list
|
||||||
|> title_changeset(%{title: title})
|
|> title_changeset(%{title: title})
|
||||||
|
|
|
@ -770,6 +770,12 @@ def get_list(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def account_lists(%{assigns: %{user: user}} = conn, %{"id" => account_id}) do
|
||||||
|
lists = Pleroma.List.get_lists_account_belongs(user, account_id)
|
||||||
|
res = ListView.render("lists.json", lists: lists)
|
||||||
|
json(conn, res)
|
||||||
|
end
|
||||||
|
|
||||||
def delete_list(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
def delete_list(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
|
with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
|
||||||
{:ok, _list} <- Pleroma.List.delete(list) do
|
{:ok, _list} <- Pleroma.List.delete(list) do
|
||||||
|
|
|
@ -119,6 +119,7 @@ defmodule Pleroma.Web.Router do
|
||||||
post("/accounts/:id/unblock", MastodonAPIController, :unblock)
|
post("/accounts/:id/unblock", MastodonAPIController, :unblock)
|
||||||
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)
|
||||||
|
get("/accounts/:id/lists", MastodonAPIController, :account_lists)
|
||||||
|
|
||||||
get("/follow_requests", MastodonAPIController, :follow_requests)
|
get("/follow_requests", MastodonAPIController, :follow_requests)
|
||||||
post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
|
post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
|
||||||
|
|
Loading…
Reference in a new issue