Merge branch 'develop' into 'hide-muted-reactions'
[akkoma] / lib / pleroma / web / api_spec / operations / emoji_reaction_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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 a unicode emoji",
47 parameters: [
48 Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
49 Operation.parameter(:emoji, :path, :string, "A single character unicode emoji",
50 required: true
51 )
52 ],
53 security: [%{"oAuth" => ["write:statuses"]}],
54 operationId: "EmojiReactionController.create",
55 responses: %{
56 200 => Operation.response("Status", "application/json", Status),
57 400 => Operation.response("Bad Request", "application/json", ApiError)
58 }
59 }
60 end
61
62 def delete_operation do
63 %Operation{
64 tags: ["Emoji Reactions"],
65 summary: "Remove a reaction to a post with a unicode emoji",
66 parameters: [
67 Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
68 Operation.parameter(:emoji, :path, :string, "A single character unicode emoji",
69 required: true
70 )
71 ],
72 security: [%{"oAuth" => ["write:statuses"]}],
73 operationId: "EmojiReactionController.delete",
74 responses: %{
75 200 => Operation.response("Status", "application/json", Status)
76 }
77 }
78 end
79
80 defp array_of_reactions_response do
81 Operation.response("Array of Emoji Reactions", "application/json", %Schema{
82 type: :array,
83 items: emoji_reaction(),
84 example: [emoji_reaction().example]
85 })
86 end
87
88 defp emoji_reaction do
89 %Schema{
90 title: "EmojiReaction",
91 type: :object,
92 properties: %{
93 name: %Schema{type: :string, description: "Emoji"},
94 count: %Schema{type: :integer, description: "Count of reactions with this emoji"},
95 me: %Schema{type: :boolean, description: "Did I react with this emoji?"},
96 accounts: %Schema{
97 type: :array,
98 items: Account,
99 description: "Array of accounts reacted with this emoji"
100 }
101 },
102 example: %{
103 "name" => "😱",
104 "count" => 1,
105 "me" => false,
106 "accounts" => [Account.schema().example]
107 }
108 }
109 end
110 end