Add since_id for activitypub fetching.
authorRoger Braun <roger@rogerbraun.net>
Tue, 21 Mar 2017 19:31:48 +0000 (20:31 +0100)
committerRoger Braun <roger@rogerbraun.net>
Tue, 21 Mar 2017 19:31:48 +0000 (20:31 +0100)
lib/pleroma/web/activity_pub/activity_pub.ex
test/web/activity_pub/activity_pub_test.exs

index 1f6ee47448ab9de0632b2cc052b7c63435d3cf03..94e52a0fb0bd6e758fac77b8d3a629efc8ce05c1 100644 (file)
@@ -7,9 +7,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     Repo.insert(%Activity{data: map})
   end
 
-  def fetch_public_activities do
+  def fetch_public_activities(opts \\ %{}) do
+    since_id = opts[:since_id] || 0
+
     query = from activity in Activity,
       where: fragment(~s(? @> '{"to": ["https://www.w3.org/ns/activitystreams#Public"]}'), activity.data),
+      where: activity.id > ^since_id,
       limit: 20,
       order_by: [desc: :inserted_at]
 
index d640bfa2bf9fc0c6fb3df342f01b5dc9c33499b2..6f636d5d1716ad362ddaec8087f8c3eeedbfb083 100644 (file)
@@ -34,5 +34,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       assert length(activities) == 20
       assert last == last_expected
     end
+
+    test "retrieves ids starting from a since_id" do
+      activities = ActivityBuilder.insert_list(30)
+      later_activities = ActivityBuilder.insert_list(10)
+      since_id = List.last(activities).id
+      last_expected = List.last(later_activities)
+
+      activities = ActivityPub.fetch_public_activities(%{since_id: since_id})
+      last = List.last(activities)
+
+      assert length(activities) == 10
+      assert last == last_expected
+    end
   end
 end