1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.EmojiReactionOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.Account
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
11 alias Pleroma.Web.ApiSpec.Schemas.Status
13 def open_api_operation(action) do
14 operation = String.to_existing_atom("#{action}_operation")
15 apply(__MODULE__, operation, [])
18 def index_operation do
20 tags: ["Emoji reactions"],
22 "Get an object of emoji to account mappings with accounts that reacted to the post",
24 Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
25 Operation.parameter(:emoji, :path, :string, "Filter by a single unicode emoji",
32 "Include reactions from muted acccounts."
35 security: [%{"oAuth" => ["read:statuses"]}],
36 operationId: "EmojiReactionController.index",
38 200 => array_of_reactions_response()
43 def create_operation do
45 tags: ["Emoji reactions"],
46 summary: "React to a post with either a unicode or custom emoji",
48 Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
53 "A single character unicode emoji, or a \:shortcode\: format emoji name",
57 security: [%{"oAuth" => ["write:statuses"]}],
58 operationId: "EmojiReactionController.create",
60 200 => Operation.response("Status", "application/json", Status),
61 400 => Operation.response("Bad Request", "application/json", ApiError)
66 def delete_operation do
68 tags: ["Emoji reactions"],
69 summary: "Remove a reaction to a post with either a unicode or custom emoji",
71 Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
76 "A single character unicode emoji, or a \:shortcode\: format emoji name",
80 security: [%{"oAuth" => ["write:statuses"]}],
81 operationId: "EmojiReactionController.delete",
83 200 => Operation.response("Status", "application/json", Status)
88 defp array_of_reactions_response do
89 Operation.response("Array of Emoji reactions", "application/json", %Schema{
91 items: emoji_reaction(),
92 example: emoji_reaction().example
96 defp emoji_reaction do
98 title: "EmojiReaction",
101 name: %Schema{type: :string, description: "Emoji"},
102 count: %Schema{type: :integer, description: "Count of reactions with this emoji"},
103 me: %Schema{type: :boolean, description: "Did I react with this emoji?"},
106 description: "URL of the emoji if it's custom - otherwise null",
113 description: "Array of accounts reacted with this emoji"
122 "accounts" => [Account.schema().example]
125 "name" => "dinosaur",
128 "url" => "https://akkoma.dev/emoji/dinosaur.png",
129 "accounts" => [Account.schema().example]