1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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 one message in the chat 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: "Create 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: "Get a list of chats that you participated in",
135 operationId: "ChatController.index",
137 Operation.parameter(:with_muted, :query, BooleanLike, "Include chats from muted users")
138 | pagination_params()
141 200 => Operation.response("The chats of the user", "application/json", chats_response())
145 "oAuth" => ["read:chats"]
151 def messages_operation do
154 summary: "Get the most recent messages of the chat",
155 operationId: "ChatController.messages",
157 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
162 "The messages in the chat",
164 chat_messages_response()
166 404 => Operation.response("Not Found", "application/json", ApiError)
170 "oAuth" => ["read:chats"]
176 def post_chat_message_operation do
179 summary: "Post a message to the chat",
180 operationId: "ChatController.post_chat_message",
182 Operation.parameter(:id, :path, :string, "The ID of the Chat")
184 requestBody: request_body("Parameters", chat_message_create()),
188 "The newly created ChatMessage",
192 400 => Operation.response("Bad Request", "application/json", ApiError),
193 422 => Operation.response("MRF Rejection", "application/json", ApiError)
197 "oAuth" => ["write:chats"]
203 def delete_message_operation do
206 summary: "delete_message",
207 operationId: "ChatController.delete_message",
209 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
210 Operation.parameter(:message_id, :path, :string, "The ID of the message")
215 "The deleted ChatMessage",
222 "oAuth" => ["write:chats"]
228 def chats_response do
230 title: "ChatsResponse",
231 description: "Response schema for multiple Chats",
239 "is_confirmed" => true,
240 "hide_followers_count" => false,
241 "is_moderator" => false,
242 "hide_favorites" => true,
243 "ap_id" => "https://dontbulling.me/users/lain",
244 "hide_follows_count" => false,
245 "hide_follows" => false,
246 "background_image" => nil,
247 "skip_thread_containment" => false,
248 "hide_followers" => false,
249 "relationship" => %{},
253 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
254 "following_count" => 0,
255 "header_static" => "https://originalpatchou.li/images/banner.png",
257 "sensitive" => false,
260 "discoverable" => false,
261 "actor_type" => "Person"
265 "statuses_count" => 1,
267 "created_at" => "2020-04-16T13:40:15.000Z",
268 "display_name" => "lain",
270 "acct" => "lain@dontbulling.me",
271 "id" => "9u6Qw6TAZANpqokMkK",
274 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
275 "username" => "lain",
276 "followers_count" => 0,
277 "header" => "https://originalpatchou.li/images/banner.png",
280 "url" => "https://dontbulling.me/users/lain"
289 def chat_messages_response do
291 title: "ChatMessagesResponse",
292 description: "Response schema for multiple ChatMessages",
299 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
300 "visible_in_picker" => false,
301 "shortcode" => "firefox",
302 "url" => "https://dontbulling.me/emoji/Firefox.gif"
305 "created_at" => "2020-04-21T15:11:46.000Z",
306 "content" => "Check this out :firefox:",
309 "account_id" => "someflakeid",
313 "account_id" => "someflakeid",
314 "content" => "Whats' up?",
318 "created_at" => "2020-04-21T15:06:45.000Z",
325 def chat_message_create do
327 title: "ChatMessageCreateRequest",
328 description: "POST body for creating an chat message",
333 description: "The content of your message. Optional if media_id is present"
335 media_id: %Schema{type: :string, description: "The id of an upload"}
338 "content" => "Hey wanna buy feet pics?",
339 "media_id" => "134234"
346 title: "MarkAsReadRequest",
347 description: "POST body for marking a number of chat messages as read",
349 required: [:last_read_id],
351 last_read_id: %Schema{
353 description: "The content of your message."
357 "last_read_id" => "abcdef12456"