WIP: List all the single-codepoint unicode emojis
This commit is contained in:
parent
57d0379b89
commit
744df89313
@ -77,6 +77,17 @@ defmodule Pleroma.Web.ApiSpec.EmojiReactionOperation do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def emoji_reactions_operation do
|
||||||
|
%Operation{
|
||||||
|
tags: ["Emoji Reactions"],
|
||||||
|
summary: "List emoji reactions recognized by the server",
|
||||||
|
operationId: "EmojiReactionController.emoji_reactions",
|
||||||
|
responses: %{
|
||||||
|
200 => emoji_reactions_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
defp array_of_reactions_response do
|
defp array_of_reactions_response do
|
||||||
Operation.response("Array of Emoji Reactions", "application/json", %Schema{
|
Operation.response("Array of Emoji Reactions", "application/json", %Schema{
|
||||||
type: :array,
|
type: :array,
|
||||||
@ -85,6 +96,13 @@ defmodule Pleroma.Web.ApiSpec.EmojiReactionOperation do
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp emoji_reactions_response do
|
||||||
|
Operation.response("List of emojis by their names", "application/json", %Schema{
|
||||||
|
type: :object,
|
||||||
|
example: %{"cookie" => "🍪", "umbrella" => "☂"}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
defp emoji_reaction do
|
defp emoji_reaction do
|
||||||
%Schema{
|
%Schema{
|
||||||
title: "EmojiReaction",
|
title: "EmojiReaction",
|
||||||
|
1369
lib/pleroma/web/pleroma_api/controllers/emoji.json
Normal file
1369
lib/pleroma/web/pleroma_api/controllers/emoji.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -91,4 +91,23 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionController do
|
|||||||
|> render("show.json", activity: activity, for: user, as: :activity)
|
|> render("show.json", activity: activity, for: user, as: :activity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@external_resource "lib/pleroma/web/pleroma_api/controllers/emoji.json"
|
||||||
|
|
||||||
|
@reactions_json File.read!(@external_resource)
|
||||||
|
|> Jason.decode!()
|
||||||
|
|> Enum.reduce(%{}, fn {name, codepoint}, acc ->
|
||||||
|
Map.put(
|
||||||
|
acc,
|
||||||
|
String.downcase(name),
|
||||||
|
[codepoint |> String.to_integer(16)] |> String.Chars.to_string()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
|> Jason.encode!()
|
||||||
|
|
||||||
|
def emoji_reactions(conn, _params) do
|
||||||
|
conn
|
||||||
|
|> put_resp_content_type("application/json")
|
||||||
|
|> send_resp(200, @reactions_json)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -348,6 +348,7 @@ defmodule Pleroma.Web.Router do
|
|||||||
scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
|
scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
|
||||||
pipe_through(:api)
|
pipe_through(:api)
|
||||||
|
|
||||||
|
get("/emoji_reactions", EmojiReactionController, :emoji_reactions)
|
||||||
get("/statuses/:id/reactions/:emoji", EmojiReactionController, :index)
|
get("/statuses/:id/reactions/:emoji", EmojiReactionController, :index)
|
||||||
get("/statuses/:id/reactions", EmojiReactionController, :index)
|
get("/statuses/:id/reactions", EmojiReactionController, :index)
|
||||||
end
|
end
|
||||||
|
@ -188,4 +188,16 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
|
|||||||
|
|
||||||
assert represented_user["id"] == other_user.id
|
assert represented_user["id"] == other_user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "/api/v1/pleroma/emoji_reactions" do
|
||||||
|
test "returns json with unicode emojis", %{conn: conn} do
|
||||||
|
emoji =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/pleroma/emoji_reactions")
|
||||||
|
|> json_response(200)
|
||||||
|
|
||||||
|
assert emoji["cookie"] == "🍪"
|
||||||
|
assert Enum.count(emoji) == 1367
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user