Add frontend preference route
[akkoma] / lib / pleroma / web / api_spec / operations / emoji_reaction_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
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
12
13 def open_api_operation(action) do
14 operation = String.to_existing_atom("#{action}_operation")
15 apply(__MODULE__, operation, [])
16 end
17
18 def index_operation do
19 %Operation{
20 tags: ["Emoji reactions"],
21 summary:
22 "Get an object of emoji to account mappings with accounts that reacted to the post",
23 parameters: [
24 Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
25 Operation.parameter(:emoji, :path, :string, "Filter by a single unicode emoji",
26 required: nil
27 ),
28 Operation.parameter(
29 :with_muted,
30 :query,
31 :boolean,
32 "Include reactions from muted acccounts."
33 )
34 ],
35 security: [%{"oAuth" => ["read:statuses"]}],
36 operationId: "EmojiReactionController.index",
37 responses: %{
38 200 => array_of_reactions_response()
39 }
40 }
41 end
42
43 def create_operation do
44 %Operation{
45 tags: ["Emoji reactions"],
46 summary: "React to a post with either a unicode or custom emoji",
47 parameters: [
48 Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
49 Operation.parameter(
50 :emoji,
51 :path,
52 :string,
53 "A single character unicode emoji, or a \:shortcode\: format emoji name",
54 required: true
55 )
56 ],
57 security: [%{"oAuth" => ["write:statuses"]}],
58 operationId: "EmojiReactionController.create",
59 responses: %{
60 200 => Operation.response("Status", "application/json", Status),
61 400 => Operation.response("Bad Request", "application/json", ApiError)
62 }
63 }
64 end
65
66 def delete_operation do
67 %Operation{
68 tags: ["Emoji reactions"],
69 summary: "Remove a reaction to a post with either a unicode or custom emoji",
70 parameters: [
71 Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
72 Operation.parameter(
73 :emoji,
74 :path,
75 :string,
76 "A single character unicode emoji, or a \:shortcode\: format emoji name",
77 required: true
78 )
79 ],
80 security: [%{"oAuth" => ["write:statuses"]}],
81 operationId: "EmojiReactionController.delete",
82 responses: %{
83 200 => Operation.response("Status", "application/json", Status)
84 }
85 }
86 end
87
88 defp array_of_reactions_response do
89 Operation.response("Array of Emoji reactions", "application/json", %Schema{
90 type: :array,
91 items: emoji_reaction(),
92 example: emoji_reaction().example
93 })
94 end
95
96 defp emoji_reaction do
97 %Schema{
98 title: "EmojiReaction",
99 type: :object,
100 properties: %{
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?"},
104 url: %Schema{
105 type: :string,
106 description: "URL of the emoji if it's custom - otherwise null",
107 nullable: true,
108 format: "url"
109 },
110 accounts: %Schema{
111 type: :array,
112 items: Account,
113 description: "Array of accounts reacted with this emoji"
114 }
115 },
116 example: [
117 %{
118 "name" => "😱",
119 "count" => 1,
120 "me" => false,
121 "url" => nil,
122 "accounts" => [Account.schema().example]
123 },
124 %{
125 "name" => "dinosaur",
126 "count" => 1,
127 "me" => false,
128 "url" => "https://akkoma.dev/emoji/dinosaur.png",
129 "accounts" => [Account.schema().example]
130 }
131 ]
132 }
133 end
134 end