2020-05-19 12:11:59 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-05-19 12:11:59 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.PleromaAPI.ScrobbleView do
|
|
|
|
use Pleroma.Web, :view
|
|
|
|
|
|
|
|
require Pleroma.Constants
|
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.HTML
|
|
|
|
alias Pleroma.Object
|
2020-08-31 21:48:24 +00:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2020-05-19 12:11:59 +00:00
|
|
|
alias Pleroma.Web.CommonAPI.Utils
|
|
|
|
alias Pleroma.Web.MastodonAPI.AccountView
|
|
|
|
|
2024-05-16 17:44:38 +00:00
|
|
|
def render("show.json", %{scrobble: %Activity{data: %{"type" => "Listen"}} = scrobble} = _opts) do
|
|
|
|
scrobble_schema_skeleton(scrobble)
|
|
|
|
end
|
2020-05-19 12:11:59 +00:00
|
|
|
|
2024-05-16 17:44:38 +00:00
|
|
|
def render("show.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do
|
2020-08-31 21:48:24 +00:00
|
|
|
user = CommonAPI.get_user(activity.data["actor"])
|
2024-05-16 17:44:38 +00:00
|
|
|
|
|
|
|
scrobble_schema_skeleton(activity)
|
|
|
|
|> Map.put(:account, AccountView.render("show.json", %{user: user, for: opts[:for]}))
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("index.json", opts) do
|
|
|
|
safe_render_many(opts.activities, __MODULE__, "show.json", opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp scrobble_schema_skeleton(%Activity{data: %{"type" => "Listen"}} = scrobble) do
|
|
|
|
object = Object.normalize(scrobble, fetch: false)
|
|
|
|
created_at = Utils.to_masto_date(scrobble.data["published"])
|
2020-05-19 12:11:59 +00:00
|
|
|
|
|
|
|
%{
|
2024-05-16 17:44:38 +00:00
|
|
|
id: scrobble.id,
|
2020-05-19 12:11:59 +00:00
|
|
|
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(),
|
2023-11-29 14:55:44 +00:00
|
|
|
externalLink: object.data["externalLink"],
|
2020-05-19 12:11:59 +00:00
|
|
|
length: object.data["length"]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|