First
[anni] / lib / pleroma / web / api_spec / operations / admin / chat_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.Admin.ChatOperation do
6   alias OpenApiSpex.Operation
7   alias Pleroma.Web.ApiSpec.Schemas.Chat
8   alias Pleroma.Web.ApiSpec.Schemas.ChatMessage
9
10   import Pleroma.Web.ApiSpec.Helpers
11
12   def open_api_operation(action) do
13     operation = String.to_existing_atom("#{action}_operation")
14     apply(__MODULE__, operation, [])
15   end
16
17   def delete_message_operation do
18     %Operation{
19       tags: ["Chat administration"],
20       summary: "Delete an individual chat message",
21       operationId: "AdminAPI.ChatController.delete_message",
22       parameters: [
23         Operation.parameter(:id, :path, :string, "The ID of the Chat"),
24         Operation.parameter(:message_id, :path, :string, "The ID of the message")
25       ],
26       responses: %{
27         200 =>
28           Operation.response(
29             "The deleted ChatMessage",
30             "application/json",
31             ChatMessage
32           )
33       },
34       security: [
35         %{
36           "oAuth" => ["admin:write:chats"]
37         }
38       ]
39     }
40   end
41
42   def messages_operation do
43     %Operation{
44       tags: ["Chat administration"],
45       summary: "Get chat's messages",
46       operationId: "AdminAPI.ChatController.messages",
47       parameters:
48         [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
49           pagination_params(),
50       responses: %{
51         200 =>
52           Operation.response(
53             "The messages in the chat",
54             "application/json",
55             Pleroma.Web.ApiSpec.ChatOperation.chat_messages_response()
56           )
57       },
58       security: [
59         %{
60           "oAuth" => ["admin:read:chats"]
61         }
62       ]
63     }
64   end
65
66   def show_operation do
67     %Operation{
68       tags: ["Chat administration"],
69       summary: "Create a chat",
70       operationId: "AdminAPI.ChatController.show",
71       parameters: [
72         Operation.parameter(
73           :id,
74           :path,
75           :string,
76           "The id of the chat",
77           required: true,
78           example: "1234"
79         )
80       ],
81       responses: %{
82         200 =>
83           Operation.response(
84             "The existing chat",
85             "application/json",
86             Chat
87           )
88       },
89       security: [
90         %{
91           "oAuth" => ["admin:read"]
92         }
93       ]
94     }
95   end
96 end