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 @@ def emoji_reactions_by(%{assigns: %{user: user}} = conn, %{"id" => activity_id})
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 @@ def react_with_emoji(%{assigns: %{user: user}} = conn, %{"id" => activity_id, "e
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 @@ test "it can handle Listen activities" 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