+
+ def render("outbox.json", %{user: user, max_id: max_qid}) do
+ # XXX: technically note_count is wrong for this, but it's better than nothing
+ info = User.user_info(user)
+
+ params = %{
+ "type" => ["Create", "Announce"],
+ "actor_id" => user.ap_id,
+ "whole_db" => true,
+ "limit" => "10"
+ }
+
+ params =
+ if max_qid != nil do
+ Map.put(params, "max_id", max_qid)
+ else
+ params
+ end
+
+ activities = ActivityPub.fetch_public_activities(params)
+ min_id = Enum.at(activities, 0).id
+
+ activities = Enum.reverse(activities)
+ max_id = Enum.at(activities, 0).id
+
+ collection =
+ Enum.map(activities, fn act ->
+ {:ok, data} = Transmogrifier.prepare_outgoing(act.data)
+ data
+ end)
+
+ iri = "#{user.ap_id}/outbox"
+
+ page = %{
+ "id" => "#{iri}?max_id=#{max_id}",
+ "type" => "OrderedCollectionPage",
+ "partOf" => iri,
+ "totalItems" => info.note_count,
+ "orderedItems" => collection,
+ "next" => "#{iri}?max_id=#{min_id - 1}"
+ }
+
+ if max_qid == nil do
+ %{
+ "id" => iri,
+ "type" => "OrderedCollection",
+ "totalItems" => info.note_count,
+ "first" => page
+ }
+ |> Map.merge(Utils.make_json_ld_header())
+ else
+ page |> Map.merge(Utils.make_json_ld_header())
+ end
+ end
+
+ def collection(collection, iri, page, _total \\ nil) do
+ offset = (page - 1) * 10
+ items = Enum.slice(collection, offset, 10)
+ items = Enum.map(items, fn user -> user.ap_id end)
+ total = _total || length(collection)
+
+ map = %{
+ "id" => "#{iri}?page=#{page}",
+ "type" => "OrderedCollectionPage",
+ "partOf" => iri,
+ "totalItems" => length(collection),
+ "orderedItems" => items
+ }
+
+ if offset < length(collection) do
+ Map.put(map, "next", "#{iri}?page=#{page + 1}")
+ end
+ end