Skip to content
Snippets Groups Projects
Commit aacdedce authored by lain's avatar lain
Browse files

Emoji Reactions: Refactor of user fetching

parent db4691a5
No related tags found
No related merge requests found
......@@ -257,8 +257,7 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity}
with %{data: %{"reactions" => emoji_reactions}} <- object do
Enum.map(emoji_reactions, fn [emoji, users] ->
users =
Enum.map(users, &User.get_cached_by_ap_id/1)
|> Enum.filter(& &1)
User.get_all_cached_by_ap_id(users)
|> Enum.map(& &1.id)
%{emoji: emoji, count: length(users), account_ids: users}
......
......@@ -49,8 +49,8 @@ def emoji_reactions_by(%{assigns: %{user: user}} = conn, %{"id" => activity_id})
emoji_reactions
|> Enum.map(fn [emoji, users] ->
users =
Enum.map(users, &User.get_cached_by_ap_id/1)
|> Enum.filter(& &1)
users
|> User.get_all_cached_by_ap_id()
%{
emoji: emoji,
......
......@@ -42,10 +42,15 @@ test "has an emoji reaction list" do
activity = Repo.get(Activity, activity.id)
status = StatusView.render("show.json", activity: activity)
assert status[:pleroma][:emoji_reactions] == [
%{emoji: "☕", count: 2, account_ids: [other_user.id, user.id]},
%{emoji: "🍵", count: 1, account_ids: [third_user.id]}
]
assert [
%{emoji: "☕", count: 2, account_ids: cofe_users},
%{emoji: "🍵", count: 1, account_ids: tee_users}
] = status[:pleroma][:emoji_reactions]
assert length(cofe_users) == 2
assert user.id in cofe_users
assert other_user.id in cofe_users
assert [third_user.id] == tee_users
end
test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment