WIP: List all the single-codepoint unicode emojis

This commit is contained in:
Haelwenn (lanodan) Monnier 2020-11-30 17:07:26 +01:00
parent 57d0379b89
commit 744df89313
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE
5 changed files with 1419 additions and 0 deletions

View File

@ -77,6 +77,17 @@ def delete_operation do
}
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
Operation.response("Array of Emoji Reactions", "application/json", %Schema{
type: :array,
@ -85,6 +96,13 @@ defp array_of_reactions_response do
})
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
%Schema{
title: "EmojiReaction",

File diff suppressed because it is too large Load Diff

View File

@ -91,4 +91,23 @@ def delete(%{assigns: %{user: user}} = conn, %{id: activity_id, emoji: emoji}) d
|> render("show.json", activity: activity, for: user, as: :activity)
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

View File

@ -348,6 +348,7 @@ defmodule Pleroma.Web.Router do
scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
pipe_through(:api)
get("/emoji_reactions", EmojiReactionController, :emoji_reactions)
get("/statuses/:id/reactions/:emoji", EmojiReactionController, :index)
get("/statuses/:id/reactions", EmojiReactionController, :index)
end

View File

@ -188,4 +188,16 @@ test "GET /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do
assert represented_user["id"] == other_user.id
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