Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
[akkoma] / lib / pleroma / web / api_spec / operations / 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.ChatOperation do
6 alias OpenApiSpex.Operation
7 alias Pleroma.Web.ApiSpec.Helpers
8 alias Pleroma.Web.ApiSpec.Schemas.ChatMessageCreateRequest
9 alias Pleroma.Web.ApiSpec.Schemas.ChatMessageResponse
10 alias Pleroma.Web.ApiSpec.Schemas.ChatMessagesResponse
11 alias Pleroma.Web.ApiSpec.Schemas.ChatResponse
12 alias Pleroma.Web.ApiSpec.Schemas.ChatsResponse
13
14 @spec open_api_operation(atom) :: Operation.t()
15 def open_api_operation(action) do
16 operation = String.to_existing_atom("#{action}_operation")
17 apply(__MODULE__, operation, [])
18 end
19
20 def create_operation do
21 %Operation{
22 tags: ["chat"],
23 summary: "Create a chat",
24 operationId: "ChatController.create",
25 parameters: [
26 Operation.parameter(
27 :ap_id,
28 :path,
29 :string,
30 "The ActivityPub id of the recipient of this chat.",
31 required: true,
32 example: "https://lain.com/users/lain"
33 )
34 ],
35 responses: %{
36 200 =>
37 Operation.response("The created or existing chat", "application/json", ChatResponse)
38 },
39 security: [
40 %{
41 "oAuth" => ["write"]
42 }
43 ]
44 }
45 end
46
47 def index_operation do
48 %Operation{
49 tags: ["chat"],
50 summary: "Get a list of chats that you participated in",
51 operationId: "ChatController.index",
52 parameters: [
53 Operation.parameter(:limit, :query, :integer, "How many results to return", example: 20),
54 Operation.parameter(:min_id, :query, :string, "Return only chats after this id"),
55 Operation.parameter(:max_id, :query, :string, "Return only chats before this id")
56 ],
57 responses: %{
58 200 => Operation.response("The chats of the user", "application/json", ChatsResponse)
59 },
60 security: [
61 %{
62 "oAuth" => ["read"]
63 }
64 ]
65 }
66 end
67
68 def messages_operation do
69 %Operation{
70 tags: ["chat"],
71 summary: "Get the most recent messages of the chat",
72 operationId: "ChatController.messages",
73 parameters: [
74 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
75 Operation.parameter(:limit, :query, :integer, "How many results to return", example: 20),
76 Operation.parameter(:min_id, :query, :string, "Return only messages after this id"),
77 Operation.parameter(:max_id, :query, :string, "Return only messages before this id")
78 ],
79 responses: %{
80 200 =>
81 Operation.response("The messages in the chat", "application/json", ChatMessagesResponse)
82 },
83 security: [
84 %{
85 "oAuth" => ["read"]
86 }
87 ]
88 }
89 end
90
91 def post_chat_message_operation do
92 %Operation{
93 tags: ["chat"],
94 summary: "Post a message to the chat",
95 operationId: "ChatController.post_chat_message",
96 parameters: [
97 Operation.parameter(:id, :path, :string, "The ID of the Chat")
98 ],
99 requestBody: Helpers.request_body("Parameters", ChatMessageCreateRequest, required: true),
100 responses: %{
101 200 =>
102 Operation.response(
103 "The newly created ChatMessage",
104 "application/json",
105 ChatMessageResponse
106 )
107 },
108 security: [
109 %{
110 "oAuth" => ["write"]
111 }
112 ]
113 }
114 end
115 end