Add featured route
This commit is contained in:
parent
b17e177335
commit
f90a7133bc
8 changed files with 118 additions and 3 deletions
51
lib/nulla_web/controllers/activitypub/featured_json.ex
Normal file
51
lib/nulla_web/controllers/activitypub/featured_json.ex
Normal file
|
@ -0,0 +1,51 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue