Browse Source

Emoji reactions: Change api format once more

revert/attachment-cleanup
lain 4 years ago
parent
commit
347f3ed2c6
4 changed files with 12 additions and 4 deletions
  1. +1
    -1
      lib/pleroma/web/mastodon_api/views/status_view.ex
  2. +6
    -1
      lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex
  3. +4
    -1
      test/web/mastodon_api/views/status_view_test.exs
  4. +1
    -1
      test/web/pleroma_api/controllers/pleroma_api_controller_test.exs

+ 1
- 1
lib/pleroma/web/mastodon_api/views/status_view.ex View File

@@ -256,7 +256,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
emoji_reactions =
with %{data: %{"reactions" => emoji_reactions}} <- object do
Enum.map(emoji_reactions, fn [emoji, users] ->
[emoji, length(users)]
%{emoji: emoji, count: length(users)}
end)
else
_ -> []


+ 6
- 1
lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex View File

@@ -49,7 +49,12 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
emoji_reactions
|> Enum.map(fn [emoji, users] ->
users = Enum.map(users, &User.get_cached_by_ap_id/1)
{emoji, AccountView.render("index.json", %{users: users, for: user, as: :user})}

%{
emoji: emoji,
count: length(users),
accounts: AccountView.render("index.json", %{users: users, for: user, as: :user})
}
end)

conn


+ 4
- 1
test/web/mastodon_api/views/status_view_test.exs View File

@@ -36,7 +36,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
activity = Repo.get(Activity, activity.id)
status = StatusView.render("show.json", activity: activity)

assert status[:pleroma][:emoji_reactions] == [["☕", 2], ["🍵", 1]]
assert status[:pleroma][:emoji_reactions] == [
%{emoji: "☕", count: 2},
%{emoji: "🍵", count: 1}
]
end

test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do


+ 1
- 1
test/web/pleroma_api/controllers/pleroma_api_controller_test.exs View File

@@ -71,7 +71,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by")
|> json_response(200)

[["🎅", [represented_user]]] = result
[%{"emoji" => "🎅", "count" => 1, "accounts" => [represented_user]}] = result
assert represented_user["id"] == other_user.id
end



Loading…
Cancel
Save