defmodule NullaWeb.ActivityPub.FeaturedJSON do @doc """ Renders a featured. """ def index(actor, notes) do Jason.OrderedObject.new( "@context": "https://www.w3.org/ns/activitystreams", id: actor.featured, type: "OrderedCollection", totalItems: length(notes), orderedItems: Enum.map(notes, &data/1) ) end defp data(note) do attachment = case note.media_attachments do [] -> [] attachments -> [ attachment: Enum.map(attachments, fn att -> Jason.OrderedObject.new( type: "Document", mediaType: att.mime_type, url: "https://#{note.actor.domain}/files/#{att.file}" ) end) ] end Jason.OrderedObject.new( "@context": "https://www.w3.org/ns/activitystreams", id: note.ap_id, type: "Note", summary: nil, inReplyTo: note.inReplyTo, published: note.published, url: note.url, attributedTo: note.actor.ap_id, to: note.to, cc: note.cc, sensitive: note.sensitive, content: note.content, contentMap: Jason.OrderedObject.new("#{note.language}": note.content), attachment: attachment ) end end