Pagination for user profiles.

This commit is contained in:
Phil Hagelberg 2019-11-04 22:49:05 -08:00
parent 8969c5522d
commit df2f59be91
2 changed files with 27 additions and 4 deletions

View File

@ -15,6 +15,8 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
plug(:put_view, Pleroma.Web.StaticFE.StaticFEView) plug(:put_view, Pleroma.Web.StaticFE.StaticFEView)
plug(:assign_id) plug(:assign_id)
@page_keys ["max_id", "min_id", "limit", "since_id", "order"]
defp get_title(%Object{data: %{"name" => name}}) when is_binary(name), defp get_title(%Object{data: %{"name" => name}}) when is_binary(name),
do: name do: name
@ -53,7 +55,8 @@ def represent(%Activity{object: %Object{data: data}} = activity, selected) do
published: data["published"], published: data["published"],
sensitive: data["sensitive"], sensitive: data["sensitive"],
selected: selected, selected: selected,
counts: get_counts(activity) counts: get_counts(activity),
id: activity.id
} }
end end
@ -68,14 +71,25 @@ def show(%{assigns: %{notice_id: notice_id}} = conn, _params) do
render(conn, "conversation.html", %{activities: timeline}) render(conn, "conversation.html", %{activities: timeline})
end 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) %User{} = user = User.get_cached_by_nickname_or_id(username_or_id)
timeline = timeline =
ActivityPub.fetch_user_activities(user, nil, %{}) ActivityPub.fetch_user_activities(user, nil, Map.take(params, @page_keys))
|> Enum.map(&represent/1) |> 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 end
def assign_id(%{path_info: ["notice", notice_id]} = conn, _opts), def assign_id(%{path_info: ["notice", notice_id]} = conn, _opts),

View File

@ -18,5 +18,14 @@
<%= for activity <- @timeline do %> <%= for activity <- @timeline do %>
<%= render("_notice.html", Map.put(activity, :selected, false)) %> <%= render("_notice.html", Map.put(activity, :selected, false)) %>
<% end %> <% 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> </div>
</main> </main>