PleromaAPIController: Fixes and refactoring.

This commit is contained in:
lain 2019-09-30 15:13:25 +02:00
parent 04a2910f33
commit 6068d2254e
2 changed files with 7 additions and 12 deletions

View File

@ -23,17 +23,12 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
with %Activity{} = activity <- Activity.get_by_id_with_object(activity_id), with %Activity{} = activity <- Activity.get_by_id_with_object(activity_id),
%Object{data: %{"reactions" => emoji_reactions}} <- Object.normalize(activity) do %Object{data: %{"reactions" => emoji_reactions}} <- Object.normalize(activity) do
reactions = reactions =
Enum.reduce(emoji_reactions, %{}, fn {emoji, users}, res -> emoji_reactions
users = |> Enum.map(fn {emoji, users} ->
users users = Enum.map(users, &User.get_cached_by_ap_id/1)
|> Enum.map(&User.get_cached_by_ap_id/1) {emoji, AccountView.render("accounts.json", %{users: users, for: user, as: :user})}
res
|> Map.put(
emoji,
AccountView.render("accounts.json", %{users: users, for: user, as: :user})
)
end) end)
|> Enum.into(%{})
conn conn
|> json(reactions) |> json(reactions)
@ -49,7 +44,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
activity = Activity.get_by_id(activity_id) do activity = Activity.get_by_id(activity_id) do
conn conn
|> put_view(StatusView) |> put_view(StatusView)
|> render("status.json", %{activity: activity, for: user, as: :activity}) |> render("show.json", %{activity: activity, for: user, as: :activity})
end end
end end

View File

@ -1263,7 +1263,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"}) {:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data) {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data)
end end
end end