1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.ChatOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
9 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
10 alias Pleroma.Web.ApiSpec.Schemas.Chat
11 alias Pleroma.Web.ApiSpec.Schemas.ChatMessage
13 import Pleroma.Web.ApiSpec.Helpers
15 @spec open_api_operation(atom) :: Operation.t()
16 def open_api_operation(action) do
17 operation = String.to_existing_atom("#{action}_operation")
18 apply(__MODULE__, operation, [])
21 def mark_as_read_operation do
24 summary: "Mark all messages in the chat as read",
25 operationId: "ChatController.mark_as_read",
26 parameters: [Operation.parameter(:id, :path, :string, "The ID of the Chat")],
27 requestBody: request_body("Parameters", mark_as_read()),
38 "oAuth" => ["write:chats"]
44 def mark_message_as_read_operation do
47 summary: "Mark a message as read",
48 operationId: "ChatController.mark_message_as_read",
50 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
51 Operation.parameter(:message_id, :path, :string, "The ID of the message")
56 "The read ChatMessage",
63 "oAuth" => ["write:chats"]
72 summary: "Retrieve a chat",
73 operationId: "ChatController.show",
100 def create_operation do
103 summary: "Create a chat",
104 operationId: "ChatController.create",
110 "The account id of the recipient of this chat",
112 example: "someflakeid"
118 "The created or existing chat",
125 "oAuth" => ["write:chats"]
131 def index_operation do
134 summary: "Retrieve list of chats (unpaginated)",
137 "Deprecated due to no support for pagination. Using [/api/v2/pleroma/chats](#operation/ChatController.index2) instead is recommended.",
138 operationId: "ChatController.index",
140 Operation.parameter(:with_muted, :query, BooleanLike, "Include chats from muted users")
143 200 => Operation.response("The chats of the user", "application/json", chats_response())
147 "oAuth" => ["read:chats"]
153 def index2_operation do
156 summary: "Retrieve list of chats",
157 operationId: "ChatController.index2",
159 Operation.parameter(:with_muted, :query, BooleanLike, "Include chats from muted users")
160 | pagination_params()
163 200 => Operation.response("The chats of the user", "application/json", chats_response())
167 "oAuth" => ["read:chats"]
173 def messages_operation do
176 summary: "Retrieve chat's messages",
177 operationId: "ChatController.messages",
179 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
184 "The messages in the chat",
186 chat_messages_response()
188 404 => Operation.response("Not Found", "application/json", ApiError)
192 "oAuth" => ["read:chats"]
198 def post_chat_message_operation do
201 summary: "Post a message to the chat",
202 operationId: "ChatController.post_chat_message",
204 Operation.parameter(:id, :path, :string, "The ID of the Chat")
206 requestBody: request_body("Parameters", chat_message_create()),
210 "The newly created ChatMessage",
214 400 => Operation.response("Bad Request", "application/json", ApiError),
215 422 => Operation.response("MRF Rejection", "application/json", ApiError)
219 "oAuth" => ["write:chats"]
225 def delete_message_operation do
228 summary: "Delete message",
229 operationId: "ChatController.delete_message",
231 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
232 Operation.parameter(:message_id, :path, :string, "The ID of the message")
237 "The deleted ChatMessage",
244 "oAuth" => ["write:chats"]
250 def chats_response do
252 title: "ChatsResponse",
253 description: "Response schema for multiple Chats",
261 "is_confirmed" => true,
262 "hide_followers_count" => false,
263 "is_moderator" => false,
264 "hide_favorites" => true,
265 "ap_id" => "https://dontbulling.me/users/lain",
266 "hide_follows_count" => false,
267 "hide_follows" => false,
268 "background_image" => nil,
269 "skip_thread_containment" => false,
270 "hide_followers" => false,
271 "relationship" => %{},
275 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
276 "following_count" => 0,
277 "header_static" => "https://originalpatchou.li/images/banner.png",
279 "sensitive" => false,
282 "discoverable" => false,
283 "actor_type" => "Person"
287 "statuses_count" => 1,
289 "created_at" => "2020-04-16T13:40:15.000Z",
290 "display_name" => "lain",
292 "acct" => "lain@dontbulling.me",
293 "id" => "9u6Qw6TAZANpqokMkK",
296 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
297 "username" => "lain",
298 "followers_count" => 0,
299 "header" => "https://originalpatchou.li/images/banner.png",
302 "url" => "https://dontbulling.me/users/lain"
311 def chat_messages_response do
313 title: "ChatMessagesResponse",
314 description: "Response schema for multiple ChatMessages",
321 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
322 "visible_in_picker" => false,
323 "shortcode" => "firefox",
324 "url" => "https://dontbulling.me/emoji/Firefox.gif"
327 "created_at" => "2020-04-21T15:11:46.000Z",
328 "content" => "Check this out :firefox:",
331 "account_id" => "someflakeid",
335 "account_id" => "someflakeid",
336 "content" => "Whats' up?",
340 "created_at" => "2020-04-21T15:06:45.000Z",
347 def chat_message_create do
349 title: "ChatMessageCreateRequest",
350 description: "POST body for creating an chat message",
355 description: "The content of your message. Optional if media_id is present"
357 media_id: %Schema{type: :string, description: "The id of an upload"}
360 "content" => "Hey wanna buy feet pics?",
361 "media_id" => "134234"
368 title: "MarkAsReadRequest",
369 description: "POST body for marking a number of chat messages as read",
371 required: [:last_read_id],
373 last_read_id: %Schema{
375 description: "The content of your message."
379 "last_read_id" => "abcdef12456"