Add an endpoint /api/v1/accounts/:id/lists to get lists to which account belongs
authorAkiraFukushima <h3.poteto@gmail.com>
Thu, 18 Oct 2018 16:46:26 +0000 (01:46 +0900)
committerAkiraFukushima <h3.poteto@gmail.com>
Thu, 18 Oct 2018 16:46:26 +0000 (01:46 +0900)
lib/pleroma/list.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/router.ex

index 53d98665bf3014561d8643f8dd17c710950aee62..a99e3245b9fedc90eca575bad87d21df93a5ba9e 100644 (file)
@@ -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})
index 499635a9df8867d07cf0ce2dde258d58cd710265..cbda069df9c1c02fc46273aaa06465d07373ca15 100644 (file)
@@ -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
index ddfaa8c423f19bb42b9ed5d5909c8a651df272c8..b531b618887ec7c33a60966f0e6f6beb8c1fd568 100644 (file)
@@ -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)