AdminAPI: list messages in a 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.FlakeID
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: ["admin", "chat"],
20 summary: "Delete an individual chat message",
21 operationId: "AdminAPI.ChatController.delete",
22 parameters: [id_param(), message_id_param()] ++ admin_api_params(),
23 security: [%{"oAuth" => ["write:chats"]}],
24 responses: %{
25 200 => empty_object_response(),
26 404 => Operation.response("Not Found", "application/json", ApiError)
27 }
28 }
29 end
30
31 def messages_operation do
32 %Operation{
33 tags: ["admin", "chat"],
34 summary: "Get the most recent messages of the chat",
35 operationId: "AdminAPI.ChatController.messages",
36 parameters:
37 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
38 pagination_params(),
39 responses: %{
40 200 =>
41 Operation.response(
42 "The messages in the chat",
43 "application/json",
44 Pleroma.Web.ApiSpec.ChatOperation.chat_messages_response()
45 )
46 },
47 security: [
48 %{
49 "oAuth" => ["read:chats"]
50 }
51 ]
52 }
53 end
54
55 def id_param do
56 Operation.parameter(:id, :path, FlakeID, "Chat ID",
57 example: "9umDrYheeY451cQnEe",
58 required: true
59 )
60 end
61
62 def message_id_param do
63 Operation.parameter(:message_id, :path, FlakeID, "Chat message ID",
64 example: "9umDrYheeY451cQnEe",
65 required: true
66 )
67 end
68 end