64 lines
1.6 KiB
Elixir
64 lines
1.6 KiB
Elixir
defmodule NullaWeb.ActivityPub.NoteJSON do
|
|
alias Nulla.Notes.Note
|
|
|
|
@doc """
|
|
Renders a single note.
|
|
"""
|
|
def show(note, likes_count, shares_count) do
|
|
data(note, likes_count, shares_count)
|
|
end
|
|
|
|
defp data(%Note{} = note, likes_count, shares_count) 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,
|
|
tag: note.tag,
|
|
replies: %{},
|
|
likes:
|
|
Jason.OrderedObject.new(
|
|
id: "#{note.ap_id}/likes",
|
|
type: "Collection",
|
|
totalItems: likes_count
|
|
),
|
|
shares:
|
|
Jason.OrderedObject.new(
|
|
id: "#{note.ap_id}/shares",
|
|
type: "Collection",
|
|
totalItems: shares_count
|
|
)
|
|
)
|
|
end
|
|
end
|