Add likes and shares to activitypub note

This commit is contained in:
Mirai Kumiko 2025-07-06 15:04:27 +02:00
parent 00ecbadeca
commit 60ca00e5d8
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278
4 changed files with 37 additions and 6 deletions

View file

@ -4,11 +4,11 @@ defmodule NullaWeb.ActivityPub.NoteJSON do
@doc """
Renders a single note.
"""
def show(note) do
data(note)
def show(note, likes_count, shares_count) do
data(note, likes_count, shares_count)
end
defp data(%Note{} = note) do
defp data(%Note{} = note, likes_count, shares_count) do
attachment =
case note.media_attachments do
[] ->
@ -44,7 +44,21 @@ defmodule NullaWeb.ActivityPub.NoteJSON do
sensitive: note.sensitive,
content: note.content,
contentMap: Jason.OrderedObject.new("#{note.language}": note.content),
attachment: attachment
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