Commit b9d0e345 authored by lain's avatar lain
Browse files

Add since_id for activitypub fetching.

parent d4cf273f
......@@ -7,9 +7,12 @@ def insert(map) when is_map(map) 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]
......
......@@ -34,5 +34,18 @@ test "retrieves a maximum of 20 activities" 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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment