logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

scrobble_view.ex (1241B)


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