From: lain <lain@soykaf.club>
Date: Mon, 11 Jan 2021 14:30:40 +0000 (+0100)
Subject: ChatMessages: Fix pagination headers.
X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=e1a547d7d3913974e1049c5dc60d46812c8abf3f;p=akkoma

ChatMessages: Fix pagination headers.

They used to contain the path parameter `id` as query param,
which would break the link.
---

diff --git a/lib/pleroma/web/controller_helper.ex b/lib/pleroma/web/controller_helper.ex
index 69188a882..2df44309c 100644
--- a/lib/pleroma/web/controller_helper.ex
+++ b/lib/pleroma/web/controller_helper.ex
@@ -67,7 +67,7 @@ defmodule Pleroma.Web.ControllerHelper do
   defp build_pagination_fields(conn, min_id, max_id, extra_params) do
     params =
       conn.params
-      |> Map.drop(Map.keys(conn.path_params))
+      |> Map.drop(Map.keys(conn.path_params) |> Enum.map(&String.to_atom/1))
       |> Map.merge(extra_params)
       |> Map.drop(@id_keys)
 
diff --git a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
index 24efeeb73..d0b520fbc 100644
--- a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
@@ -211,12 +211,12 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
 
       assert String.match?(
                next,
-               ~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&max_id=.*; rel=\"next\"$)
+               ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*; rel=\"next\"$)
              )
 
       assert String.match?(
                prev,
-               ~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&min_id=.*; rel=\"prev\"$)
+               ~r(#{api_endpoint}.*/messages\?limit=\d+&min_id=.*; rel=\"prev\"$)
              )
 
       assert length(result) == 20
@@ -229,12 +229,12 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
 
       assert String.match?(
                next,
-               ~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&max_id=.*; rel=\"next\"$)
+               ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*; rel=\"next\"$)
              )
 
       assert String.match?(
                prev,
-               ~r(#{api_endpoint}.*/messages\?id=.*&limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$)
+               ~r(#{api_endpoint}.*/messages\?limit=\d+&max_id=.*&min_id=.*; rel=\"prev\"$)
              )
 
       assert length(result) == 10