mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2025-04-23 21:39:18 -04:00
Merge branch 'neetzsche/include-scrobbles-with-account' into 'develop'
Include scrobbles with account See merge request pleroma/pleroma!3975
This commit is contained in:
commit
3960c31294
4 changed files with 33 additions and 12 deletions
1
changelog.d/include-scrobbles-with-account.add
Normal file
1
changelog.d/include-scrobbles-with-account.add
Normal file
|
@ -0,0 +1 @@
|
|||
Includes five most scrobbles, when available, in the #account field with statuses
|
|
@ -9,9 +9,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.UserNote
|
||||
alias Pleroma.UserRelationship
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.MediaProxy
|
||||
alias Pleroma.Web.PleromaAPI.ScrobbleView
|
||||
|
||||
def render("index.json", %{users: users} = opts) do
|
||||
reading_user = opts[:for]
|
||||
|
@ -269,6 +271,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
nil
|
||||
end
|
||||
|
||||
scrobbles =
|
||||
ActivityPub.fetch_user_abstract_activities(user, opts[:for], %{
|
||||
type: "Listen",
|
||||
limit: 5,
|
||||
id: user.id
|
||||
})
|
||||
|
||||
last_status_at =
|
||||
user.last_status_at &&
|
||||
user.last_status_at |> NaiveDateTime.to_date() |> Date.to_iso8601()
|
||||
|
@ -321,7 +330,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
skip_thread_containment: user.skip_thread_containment,
|
||||
background_image: image_url(user.background) |> MediaProxy.url(),
|
||||
accepts_chat_messages: user.accepts_chat_messages,
|
||||
favicon: favicon
|
||||
favicon: favicon,
|
||||
scrobbles: render_many(scrobbles, ScrobbleView, "show.json")
|
||||
}
|
||||
}
|
||||
|> maybe_put_role(user, opts[:for])
|
||||
|
|
|
@ -14,15 +14,27 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleView do
|
|||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
|
||||
def render("show.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
def render("show.json", %{scrobble: %Activity{data: %{"type" => "Listen"}} = scrobble} = _opts) do
|
||||
scrobble_schema_skeleton(scrobble)
|
||||
end
|
||||
|
||||
def render("show.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do
|
||||
user = CommonAPI.get_user(activity.data["actor"])
|
||||
created_at = Utils.to_masto_date(activity.data["published"])
|
||||
|
||||
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"])
|
||||
|
||||
%{
|
||||
id: activity.id,
|
||||
account: AccountView.render("show.json", %{user: user, for: opts[:for]}),
|
||||
id: scrobble.id,
|
||||
created_at: created_at,
|
||||
title: object.data["title"] |> HTML.strip_tags(),
|
||||
artist: object.data["artist"] |> HTML.strip_tags(),
|
||||
|
@ -31,8 +43,4 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleView do
|
|||
length: object.data["length"]
|
||||
}
|
||||
end
|
||||
|
||||
def render("index.json", opts) do
|
||||
safe_render_many(opts.activities, __MODULE__, "show.json", opts)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -96,7 +96,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
hide_follows_count: false,
|
||||
relationship: %{},
|
||||
skip_thread_containment: false,
|
||||
accepts_chat_messages: nil
|
||||
accepts_chat_messages: nil,
|
||||
scrobbles: []
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -340,7 +341,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
hide_follows_count: false,
|
||||
relationship: %{},
|
||||
skip_thread_containment: false,
|
||||
accepts_chat_messages: nil
|
||||
accepts_chat_messages: nil,
|
||||
scrobbles: []
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue