Skip to content
Snippets Groups Projects
Commit cda01285 authored by lain's avatar lain
Browse files

Add pagination to notifications.

parent f1d9f2f6
No related branches found
No related tags found
No related merge requests found
......@@ -11,12 +11,28 @@ defmodule Pleroma.Notification do
timestamps()
end
# TODO: Make generic and unify (see activity_pub.ex)
defp restrict_max(query, %{"max_id" => max_id}) do
from activity in query, where: activity.id < ^max_id
end
defp restrict_max(query, _), do: query
defp restrict_since(query, %{"since_id" => since_id}) do
from activity in query, where: activity.id > ^since_id
end
defp restrict_since(query, _), do: query
def for_user(user, opts \\ %{}) do
query = from n in Notification,
where: n.user_id == ^user.id,
order_by: [desc: n.id],
preload: [:activity],
limit: 20
query = query
|> restrict_since(opts)
|> restrict_max(opts)
Repo.all(query)
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment