Add max_id fetching to activity fetching.
authorRoger Braun <roger@rogerbraun.net>
Wed, 12 Apr 2017 15:11:01 +0000 (17:11 +0200)
committerRoger Braun <roger@rogerbraun.net>
Wed, 12 Apr 2017 15:12:00 +0000 (17:12 +0200)
lib/pleroma/web/activity_pub/activity_pub.ex
test/web/activity_pub/activity_pub_test.exs

index ec9c5e97027bbc81fe01d9bdd33e6be34eccf0ee..75e4101f281d8a7b41e43891993a0407f2075cad 100644 (file)
@@ -54,6 +54,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     query = from activity in query,
       where: activity.id > ^since_id
 
+    query = if opts["max_id"] do
+      from activity in query, where: activity.id < ^opts["max_id"]
+    else
+      query
+    end
+
     Repo.all(query)
     |> Enum.reverse
   end
index 2c6f67621d23a6220e4c494e65bbf9d3284e1da5..5cfd46238b1077eabcadf1655f68188af9c4c34c 100644 (file)
@@ -94,6 +94,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       assert length(activities) == 10
       assert last == last_expected
     end
+
+    test "retrieves ids up to max_id" do
+      _first_activities = ActivityBuilder.insert_list(10)
+      activities = ActivityBuilder.insert_list(20)
+      later_activities = ActivityBuilder.insert_list(10)
+      max_id = List.first(later_activities).id
+      last_expected = List.last(activities)
+
+      activities = ActivityPub.fetch_public_activities(%{"max_id" => max_id})
+      last = List.last(activities)
+
+      assert length(activities) == 20
+      assert last == last_expected
+    end
   end
 
   describe "uploading files" do