From 9c61f605582520368d61a31e562710f383fab9c1 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Fri, 9 Feb 2018 21:41:30 +0900 Subject: [PATCH 1/4] introduce max_id parameter in feed.atom --- lib/pleroma/web/ostatus/ostatus_controller.ex | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index d442d16fd..203b6e985 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -25,6 +25,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do order_by: [desc: :id] activities = query + |> restrict_max(opts) |> Repo.all response = user @@ -54,6 +55,11 @@ defmodule Pleroma.Web.OStatus.OStatusController do 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 {:ok, body, _conn} = read_body(conn) {:ok, doc} = decode_or_retry(body) From 7124f12a94478206f600b93055e0a82b945de858 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Fri, 9 Feb 2018 21:46:05 +0900 Subject: [PATCH 2/4] introduce max_id parameter in feed.atom (debug) --- lib/pleroma/web/ostatus/ostatus_controller.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/ostatus/ostatus_controller.ex b/lib/pleroma/web/ostatus/ostatus_controller.ex index 203b6e985..4d48c5d2b 100644 --- a/lib/pleroma/web/ostatus/ostatus_controller.ex +++ b/lib/pleroma/web/ostatus/ostatus_controller.ex @@ -17,7 +17,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do end end - def feed(conn, %{"nickname" => nickname}) do + def feed(conn, %{"nickname" => nickname} = params) do user = User.get_cached_by_nickname(nickname) query = from activity in Activity, where: fragment("?->>'actor' = ?", activity.data, ^user.ap_id), @@ -25,7 +25,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do order_by: [desc: :id] activities = query - |> restrict_max(opts) + |> restrict_max(params) |> Repo.all response = user From a61f21ff4f825bc11b9d1c7c23baa3d2820cd718 Mon Sep 17 00:00:00 2001 From: hakabahitoyo Date: Fri, 9 Feb 2018 23:03:28 +0900 Subject: [PATCH 3/4] print element in atom.feed --- lib/pleroma/web/ostatus/feed_representer.ex | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/ostatus/feed_representer.ex b/lib/pleroma/web/ostatus/feed_representer.ex index 10860ce04..8461b2b9f 100644 --- a/lib/pleroma/web/ostatus/feed_representer.ex +++ b/lib/pleroma/web/ostatus/feed_representer.ex @@ -10,6 +10,8 @@ defmodule Pleroma.Web.OStatus.FeedRepresenter do h = fn(str) -> [to_charlist(str)] end + last_activity = List.last(activities) + entries = activities |> Enum.map(fn(activity) -> {:entry, ActivityRepresenter.to_simple_form(activity, user)} @@ -32,7 +34,15 @@ defmodule Pleroma.Web.OStatus.FeedRepresenter do {:link, [rel: 'salmon', href: h.(OStatus.salmon_path(user))], []}, {:link, [rel: 'self', href: h.(OStatus.feed_path(user)), type: 'application/atom+xml'], []}, {: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 From 3c80d9b27764817fcfdc4f7663f36147a9411b61 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 12 Feb 2018 08:15:03 +0100 Subject: [PATCH 4/4] Fix spec. --- test/web/ostatus/feed_representer_test.exs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs index e10936366..5b8eabcb9 100644 --- a/test/web/ostatus/feed_representer_test.exs +++ b/test/web/ostatus/feed_representer_test.exs @@ -33,6 +33,7 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do #{user_xml} + #{entry_xml}