forked from AkkomaGang/akkoma
mastodon api: implement rendering of listen activities
This commit is contained in:
parent
c3d09921e4
commit
b7877e9b1c
2 changed files with 26 additions and 0 deletions
|
@ -368,6 +368,23 @@ def render("attachment.json", %{attachment: attachment}) do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render("listen.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do
|
||||||
|
object = Object.normalize(activity)
|
||||||
|
|
||||||
|
user = get_user(activity.data["actor"])
|
||||||
|
created_at = Utils.to_masto_date(activity.data["published"])
|
||||||
|
|
||||||
|
%{
|
||||||
|
id: activity.id,
|
||||||
|
account: AccountView.render("account.json", %{user: user, for: opts[:for]}),
|
||||||
|
created_at: created_at,
|
||||||
|
title: object.data["title"] |> HTML.strip_tags(),
|
||||||
|
artist: object.data["artist"] |> HTML.strip_tags(),
|
||||||
|
album: object.data["album"] |> HTML.strip_tags(),
|
||||||
|
length: object.data["length"]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def render("poll.json", %{object: object} = opts) do
|
def render("poll.json", %{object: object} = opts) do
|
||||||
{multiple, options} =
|
{multiple, options} =
|
||||||
case object.data do
|
case object.data do
|
||||||
|
|
|
@ -608,4 +608,13 @@ test "visibility/list" do
|
||||||
|
|
||||||
assert status.visibility == "list"
|
assert status.visibility == "list"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "successfully renders a Listen activity (pleroma extension)" do
|
||||||
|
listen_activity = insert(:listen)
|
||||||
|
|
||||||
|
status = StatusView.render("listen.json", activity: listen_activity)
|
||||||
|
|
||||||
|
assert status.length == listen_activity.data["object"]["length"]
|
||||||
|
assert status.title == listen_activity.data["object"]["title"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue