forked from AkkomaGang/akkoma
Merge branch 'hakabahitoyo/pleroma-feature/atom-feed-pagination' into develop
This commit is contained in:
commit
91928b06ab
3 changed files with 19 additions and 2 deletions
|
@ -10,6 +10,8 @@ def to_simple_form(user, activities, _users) do
|
||||||
|
|
||||||
h = fn(str) -> [to_charlist(str)] end
|
h = fn(str) -> [to_charlist(str)] end
|
||||||
|
|
||||||
|
last_activity = List.last(activities)
|
||||||
|
|
||||||
entries = activities
|
entries = activities
|
||||||
|> Enum.map(fn(activity) ->
|
|> Enum.map(fn(activity) ->
|
||||||
{:entry, ActivityRepresenter.to_simple_form(activity, user)}
|
{:entry, ActivityRepresenter.to_simple_form(activity, user)}
|
||||||
|
@ -32,7 +34,15 @@ def to_simple_form(user, activities, _users) do
|
||||||
{:link, [rel: 'salmon', href: h.(OStatus.salmon_path(user))], []},
|
{:link, [rel: 'salmon', href: h.(OStatus.salmon_path(user))], []},
|
||||||
{:link, [rel: 'self', href: h.(OStatus.feed_path(user)), type: 'application/atom+xml'], []},
|
{:link, [rel: 'self', href: h.(OStatus.feed_path(user)), type: 'application/atom+xml'], []},
|
||||||
{:author, UserRepresenter.to_simple_form(user)},
|
{:author, UserRepresenter.to_simple_form(user)},
|
||||||
] ++ entries
|
] ++
|
||||||
|
if last_activity do
|
||||||
|
[{:link, [rel: 'next',
|
||||||
|
href: to_charlist(OStatus.feed_path(user)) ++ '?max_id=' ++ to_charlist(last_activity.id),
|
||||||
|
type: 'application/atom+xml'], []}]
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
++ entries
|
||||||
}]
|
}]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,7 @@ def feed_redirect(conn, %{"nickname" => nickname}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def feed(conn, %{"nickname" => nickname}) do
|
def feed(conn, %{"nickname" => nickname} = params) do
|
||||||
user = User.get_cached_by_nickname(nickname)
|
user = User.get_cached_by_nickname(nickname)
|
||||||
query = from activity in Activity,
|
query = from activity in Activity,
|
||||||
where: fragment("?->>'actor' = ?", activity.data, ^user.ap_id),
|
where: fragment("?->>'actor' = ?", activity.data, ^user.ap_id),
|
||||||
|
@ -25,6 +25,7 @@ def feed(conn, %{"nickname" => nickname}) do
|
||||||
order_by: [desc: :id]
|
order_by: [desc: :id]
|
||||||
|
|
||||||
activities = query
|
activities = query
|
||||||
|
|> restrict_max(params)
|
||||||
|> Repo.all
|
|> Repo.all
|
||||||
|
|
||||||
response = user
|
response = user
|
||||||
|
@ -54,6 +55,11 @@ defp decode_or_retry(body) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
def salmon_incoming(conn, _) do
|
def salmon_incoming(conn, _) do
|
||||||
{:ok, body, _conn} = read_body(conn)
|
{:ok, body, _conn} = read_body(conn)
|
||||||
{:ok, doc} = decode_or_retry(body)
|
{:ok, doc} = decode_or_retry(body)
|
||||||
|
|
|
@ -33,6 +33,7 @@ test "returns a feed of the last 20 items of the user" do
|
||||||
<author>
|
<author>
|
||||||
#{user_xml}
|
#{user_xml}
|
||||||
</author>
|
</author>
|
||||||
|
<link rel="next" href="#{OStatus.feed_path(user)}?max_id=#{note_activity.id}" type="application/atom+xml" />
|
||||||
<entry>
|
<entry>
|
||||||
#{entry_xml}
|
#{entry_xml}
|
||||||
</entry>
|
</entry>
|
||||||
|
|
Loading…
Reference in a new issue