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",
143 BooleanLike.schema(),
144 "Include chats from muted users"
148 200 => Operation.response("The chats of the user", "application/json", chats_response())
152 "oAuth" => ["read:chats"]
158 def index2_operation do
161 summary: "Retrieve list of chats",
162 operationId: "ChatController.index2",
167 BooleanLike.schema(),
168 "Include chats from muted users"
170 | pagination_params()
173 200 => Operation.response("The chats of the user", "application/json", chats_response())
177 "oAuth" => ["read:chats"]
183 def messages_operation do
186 summary: "Retrieve chat's messages",
187 operationId: "ChatController.messages",
189 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
194 "The messages in the chat",
196 chat_messages_response()
198 404 => Operation.response("Not Found", "application/json", ApiError)
202 "oAuth" => ["read:chats"]
208 def post_chat_message_operation do
211 summary: "Post a message to the chat",
212 operationId: "ChatController.post_chat_message",
214 Operation.parameter(:id, :path, :string, "The ID of the Chat")
216 requestBody: request_body("Parameters", chat_message_create()),
220 "The newly created ChatMessage",
224 400 => Operation.response("Bad Request", "application/json", ApiError),
225 422 => Operation.response("MRF Rejection", "application/json", ApiError)
229 "oAuth" => ["write:chats"]
235 def delete_message_operation do
238 summary: "Delete message",
239 operationId: "ChatController.delete_message",
241 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
242 Operation.parameter(:message_id, :path, :string, "The ID of the message")
247 "The deleted ChatMessage",
254 "oAuth" => ["write:chats"]
260 def chats_response do
262 title: "ChatsResponse",
263 description: "Response schema for multiple Chats",
271 "is_confirmed" => true,
272 "hide_followers_count" => false,
273 "is_moderator" => false,
274 "hide_favorites" => true,
275 "ap_id" => "https://dontbulling.me/users/lain",
276 "hide_follows_count" => false,
277 "hide_follows" => false,
278 "background_image" => nil,
279 "skip_thread_containment" => false,
280 "hide_followers" => false,
281 "relationship" => %{},
285 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
286 "following_count" => 0,
287 "header_static" => "https://originalpatchou.li/images/banner.png",
289 "sensitive" => false,
292 "discoverable" => false,
293 "actor_type" => "Person"
297 "statuses_count" => 1,
299 "created_at" => "2020-04-16T13:40:15.000Z",
300 "display_name" => "lain",
302 "acct" => "lain@dontbulling.me",
303 "id" => "9u6Qw6TAZANpqokMkK",
306 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
307 "username" => "lain",
308 "followers_count" => 0,
309 "header" => "https://originalpatchou.li/images/banner.png",
312 "url" => "https://dontbulling.me/users/lain"
321 def chat_messages_response do
323 title: "ChatMessagesResponse",
324 description: "Response schema for multiple ChatMessages",
331 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
332 "visible_in_picker" => false,
333 "shortcode" => "firefox",
334 "url" => "https://dontbulling.me/emoji/Firefox.gif"
337 "created_at" => "2020-04-21T15:11:46.000Z",
338 "content" => "Check this out :firefox:",
341 "account_id" => "someflakeid",
345 "account_id" => "someflakeid",
346 "content" => "Whats' up?",
350 "created_at" => "2020-04-21T15:06:45.000Z",
357 def chat_message_create do
359 title: "ChatMessageCreateRequest",
360 description: "POST body for creating an chat message",
365 description: "The content of your message. Optional if media_id is present"
367 media_id: %Schema{type: :string, description: "The id of an upload"}
370 "content" => "Hey wanna buy feet pics?",
371 "media_id" => "134234"
378 title: "MarkAsReadRequest",
379 description: "POST body for marking a number of chat messages as read",
381 required: [:last_read_id],
383 last_read_id: %Schema{
385 description: "The content of your message."
389 "last_read_id" => "abcdef12456"