1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.ScrobbleView do
8 require Pleroma.Constants
10 alias Pleroma.Activity
13 alias Pleroma.Web.CommonAPI.Utils
14 alias Pleroma.Web.MastodonAPI.AccountView
15 alias Pleroma.Web.MastodonAPI.StatusView
17 def render("show.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do
18 object = Object.normalize(activity)
20 user = StatusView.get_user(activity.data["actor"])
21 created_at = Utils.to_masto_date(activity.data["published"])
25 account: AccountView.render("show.json", %{user: user, for: opts[:for]}),
26 created_at: created_at,
27 title: object.data["title"] |> HTML.strip_tags(),
28 artist: object.data["artist"] |> HTML.strip_tags(),
29 album: object.data["album"] |> HTML.strip_tags(),
30 length: object.data["length"]
34 def render("index.json", opts) do
35 safe_render_many(opts.activities, __MODULE__, "show.json", opts)