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