Pagination for user profiles.
authorPhil Hagelberg <phil@hagelb.org>
Tue, 5 Nov 2019 06:49:05 +0000 (22:49 -0800)
committerPhil Hagelberg <phil@hagelb.org>
Sun, 10 Nov 2019 02:08:08 +0000 (18:08 -0800)
lib/pleroma/web/static_fe/static_fe_controller.ex
lib/pleroma/web/templates/static_fe/static_fe/profile.html.eex

index a00c6db4fc383d7b823fea7bf7c87684ace3fb78..9f4eeaa3659daa1306777e533e8490ee35cd11c3 100644 (file)
@@ -15,6 +15,8 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
   plug(:put_view, Pleroma.Web.StaticFE.StaticFEView)
   plug(:assign_id)
 
+  @page_keys ["max_id", "min_id", "limit", "since_id", "order"]
+
   defp get_title(%Object{data: %{"name" => name}}) when is_binary(name),
     do: name
 
@@ -53,7 +55,8 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
       published: data["published"],
       sensitive: data["sensitive"],
       selected: selected,
-      counts: get_counts(activity)
+      counts: get_counts(activity),
+      id: activity.id
     }
   end
 
@@ -68,14 +71,25 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
     render(conn, "conversation.html", %{activities: timeline})
   end
 
-  def show(%{assigns: %{username_or_id: username_or_id}} = conn, _params) do
+  def show(%{assigns: %{username_or_id: username_or_id}} = conn, params) do
     %User{} = user = User.get_cached_by_nickname_or_id(username_or_id)
 
     timeline =
-      ActivityPub.fetch_user_activities(user, nil, %{})
+      ActivityPub.fetch_user_activities(user, nil, Map.take(params, @page_keys))
       |> Enum.map(&represent/1)
 
-    render(conn, "profile.html", %{user: user, timeline: timeline})
+    prev_page_id =
+      (params["min_id"] || params["max_id"]) &&
+        List.first(timeline) && List.first(timeline).id
+
+    next_page_id = List.last(timeline) && List.last(timeline).id
+
+    render(conn, "profile.html", %{
+      user: user,
+      timeline: timeline,
+      prev_page_id: prev_page_id,
+      next_page_id: next_page_id
+    })
   end
 
   def assign_id(%{path_info: ["notice", notice_id]} = conn, _opts),
index fa3df3b4ef9acf70f30557df43c989424a19d38c..94063c92d631b2fd854b9e4b69f55eb20eb71884 100644 (file)
     <%= for activity <- @timeline do %>
       <%= render("_notice.html", Map.put(activity, :selected, false)) %>
     <% end %>
+    <p id="pagination">
+      <%= if @prev_page_id do %>
+        <%= link "«", to: "?min_id=" <> @prev_page_id %>
+      <% end %>
+      <%= if @prev_page_id && @next_page_id, do: " | " %>
+      <%= if @next_page_id do %>
+        <%= link "»", to: "?max_id=" <> @next_page_id %>
+      <% end %>
+    </p>
   </div>
 </main>