aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAkiraFukushima <h3.poteto@gmail.com>2018-10-19 01:46:26 +0900
committerAkiraFukushima <h3.poteto@gmail.com>2018-10-19 01:46:26 +0900
commite8c698af410639af52d89efc48f1433cd5404372 (patch)
tree837a5687b4e8f329ba8e5950b89cadff22d3fd81 /lib
parentad3181895c2ce14191ca4ada0d86346947428610 (diff)
downloadpleroma-e8c698af410639af52d89efc48f1433cd5404372.tar.gz
Add an endpoint /api/v1/accounts/:id/lists to get lists to which account belongs
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/list.ex11
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex6
-rw-r--r--lib/pleroma/web/router.ex1
3 files changed, 18 insertions, 0 deletions
diff --git a/lib/pleroma/list.ex b/lib/pleroma/list.ex
index 53d98665b..a99e3245b 100644
--- a/lib/pleroma/list.ex
+++ b/lib/pleroma/list.ex
@@ -69,6 +69,17 @@ defmodule Pleroma.List do
Repo.all(query)
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
list
|> title_changeset(%{title: title})
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 499635a9d..cbda069df 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -770,6 +770,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
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
with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
{:ok, _list} <- Pleroma.List.delete(list) do
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index ddfaa8c42..b531b6188 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -119,6 +119,7 @@ defmodule Pleroma.Web.Router do
post("/accounts/:id/unblock", MastodonAPIController, :unblock)
post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
+ get("/accounts/:id/lists", MastodonAPIController, :account_lists)
get("/follow_requests", MastodonAPIController, :follow_requests)
post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)