pagination for remote emoji packs
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Sat, 27 Jun 2020 11:33:49 +0000 (14:33 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Thu, 24 Sep 2020 06:12:39 +0000 (09:12 +0300)
lib/pleroma/emoji/pack.ex
lib/pleroma/web/api_spec/operations/pleroma_emoji_pack_operation.ex
lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex
test/web/pleroma_api/controllers/emoji_pack_controller_test.exs

index 9901aa8328cb412f19c4a034ed188ccc717fe8b4..4420eff5aa19c7b148afff906c0b454e58a434d7 100644 (file)
@@ -198,13 +198,13 @@ defmodule Pleroma.Emoji.Pack do
     end
   end
 
-  @spec list_remote(String.t()) :: {:ok, map()} | {:error, atom()}
-  def list_remote(url) do
-    uri = url |> String.trim() |> URI.parse()
+  @spec list_remote(keyword()) :: {:ok, map()} | {:error, atom()}
+  def list_remote(opts) do
+    uri = opts[:url] |> String.trim() |> URI.parse()
 
     with :ok <- validate_shareable_packs_available(uri) do
       uri
-      |> URI.merge("/api/pleroma/emoji/packs")
+      |> URI.merge("/api/pleroma/emoji/packs?page=#{opts[:page]}&page_size=#{opts[:page_size]}")
       |> http_get()
     end
   end
index 87ee5feb407481cf3e2e1b88d06fdf29c9b8dcf0..79f52dcb3afdf43c2c282a8db91b2c945748ce7f 100644 (file)
@@ -19,7 +19,21 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiPackOperation do
       tags: ["Emoji Packs"],
       summary: "Make request to another instance for emoji packs list",
       security: [%{"oAuth" => ["write"]}],
-      parameters: [url_param()],
+      parameters: [
+        url_param(),
+        Operation.parameter(
+          :page,
+          :query,
+          %Schema{type: :integer, default: 1},
+          "Page"
+        ),
+        Operation.parameter(
+          :page_size,
+          :query,
+          %Schema{type: :integer, default: 30},
+          "Number of emoji to return"
+        )
+      ],
       operationId: "PleromaAPI.EmojiPackController.remote",
       responses: %{
         200 => emoji_packs_response(),
index e3969fee103dd2bf9b2c73e48f814b8d8d4c72d4..6696f8b92ede162859608cad724db090d987f5b0 100644 (file)
@@ -23,8 +23,9 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackController do
 
   defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaEmojiPackOperation
 
-  def remote(conn, %{url: url}) do
-    with {:ok, packs} <- Pack.list_remote(url) do
+  def remote(conn, params) do
+    with {:ok, packs} <-
+           Pack.list_remote(url: params.url, page_size: params.page_size, page: params.page) do
       json(conn, packs)
     else
       {:error, :not_shareable} ->
index 068755936887e9d6de04d5984211d8fc665a2ff8..95fd78c7e1e75f60b86b55fbca6428167a5f78ff 100644 (file)
@@ -102,7 +102,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
     test "shareable instance", %{admin_conn: admin_conn, conn: conn} do
       resp =
         conn
-        |> get("/api/pleroma/emoji/packs")
+        |> get("/api/pleroma/emoji/packs?page=2&page_size=1")
         |> json_response_and_validate_schema(200)
 
       mock(fn
@@ -112,12 +112,12 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
         %{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
           json(%{metadata: %{features: ["shareable_emoji_packs"]}})
 
-        %{method: :get, url: "https://example.com/api/pleroma/emoji/packs"} ->
+        %{method: :get, url: "https://example.com/api/pleroma/emoji/packs?page=2&page_size=1"} ->
           json(resp)
       end)
 
       assert admin_conn
-             |> get("/api/pleroma/emoji/packs/remote?url=https://example.com")
+             |> get("/api/pleroma/emoji/packs/remote?url=https://example.com&page=2&page_size=1")
              |> json_response_and_validate_schema(200) == resp
     end