AdminAPI: show chat
[akkoma] / lib / pleroma / web / api_spec / operations / admin / chat_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.Admin.ChatOperation do
6 alias OpenApiSpex.Operation
7 alias Pleroma.Web.ApiSpec.Schemas.ApiError
8 alias Pleroma.Web.ApiSpec.Schemas.Chat
9 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
10
11 import Pleroma.Web.ApiSpec.Helpers
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 delete_message_operation do
19 %Operation{
20 tags: ["admin", "chat"],
21 summary: "Delete an individual chat message",
22 operationId: "AdminAPI.ChatController.delete",
23 parameters: [id_param(), message_id_param()] ++ admin_api_params(),
24 security: [%{"oAuth" => ["write:chats"]}],
25 responses: %{
26 200 => empty_object_response(),
27 404 => Operation.response("Not Found", "application/json", ApiError)
28 }
29 }
30 end
31
32 def messages_operation do
33 %Operation{
34 tags: ["admin", "chat"],
35 summary: "Get the most recent messages of the chat",
36 operationId: "AdminAPI.ChatController.messages",
37 parameters:
38 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
39 pagination_params(),
40 responses: %{
41 200 =>
42 Operation.response(
43 "The messages in the chat",
44 "application/json",
45 Pleroma.Web.ApiSpec.ChatOperation.chat_messages_response()
46 )
47 },
48 security: [
49 %{
50 "oAuth" => ["read:chats"]
51 }
52 ]
53 }
54 end
55
56 def show_operation do
57 %Operation{
58 tags: ["chat"],
59 summary: "Create a chat",
60 operationId: "AdminAPI.ChatController.show",
61 parameters: [
62 Operation.parameter(
63 :id,
64 :path,
65 :string,
66 "The id of the chat",
67 required: true,
68 example: "1234"
69 )
70 ],
71 responses: %{
72 200 =>
73 Operation.response(
74 "The existing chat",
75 "application/json",
76 Chat
77 )
78 },
79 security: [
80 %{
81 "oAuth" => ["read"]
82 }
83 ]
84 }
85 end
86
87 def id_param do
88 Operation.parameter(:id, :path, FlakeID, "Chat ID",
89 example: "9umDrYheeY451cQnEe",
90 required: true
91 )
92 end
93
94 def message_id_param do
95 Operation.parameter(:message_id, :path, FlakeID, "Chat message ID",
96 example: "9umDrYheeY451cQnEe",
97 required: true
98 )
99 end
100 end