nulla/lib/nulla_web/controllers/activitypub/outbox_json.ex
2025-07-05 15:20:40 +02:00

44 lines
1.1 KiB
Elixir

defmodule NullaWeb.ActivityPub.OutboxJSON do
@doc """
Renders an outbox.
"""
def index(actor, total) do
Jason.OrderedObject.new(
"@context": "https://www.w3.org/ns/activitystreams",
id: actor.outbox,
type: "OrderedCollection",
totalItems: total,
first: "#{actor.outbox}?page=true",
last: "#{actor.outbox}?min_id=0&page=true"
)
end
def show(actor, activities, max_id, min_id) do
Jason.OrderedObject.new(
"@context": [
"https://www.w3.org/ns/activitystreams",
Jason.OrderedObject.new(
sensitive: "as:sensitive",
Hashtag: "as:Hashtag"
)
],
id: "#{actor.outbox}?page=true",
type: "OrderedCollectionPage",
next: "#{actor.outbox}?max_id=#{max_id}&page=true",
prev: "#{actor.outbox}?min_id=#{min_id}&page=true",
partOf: actor.outbox,
orderedItems: Enum.map(activities, &data/1)
)
end
defp data(activity) do
Jason.OrderedObject.new(
id: activity.ap_id,
type: activity.type,
actor: activity.actor,
object: activity.object,
to: activity.to,
cc: activity.cc
)
end
end