50 lines
1.2 KiB
Elixir
50 lines
1.2 KiB
Elixir
defmodule NullaWeb.ActivityPub.NoteJSON do
|
|
alias Nulla.Notes.Note
|
|
|
|
@doc """
|
|
Renders a single note.
|
|
"""
|
|
def show(note) do
|
|
data(note)
|
|
end
|
|
|
|
defp data(%Note{} = 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",
|
|
Jason.OrderedObject.new(sensitive: "as:sensitive")
|
|
],
|
|
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
|