1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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.Chat
10 alias Pleroma.Web.ApiSpec.Schemas.ChatMessage
12 import Pleroma.Web.ApiSpec.Helpers
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, [])
20 def mark_as_read_operation do
23 summary: "Mark all messages in the chat as read",
24 operationId: "ChatController.mark_as_read",
25 parameters: [Operation.parameter(:id, :path, :string, "The ID of the Chat")],
26 requestBody: request_body("Parameters", mark_as_read()),
37 "oAuth" => ["write:chats"]
43 def mark_message_as_read_operation do
46 summary: "Mark one message in the chat as read",
47 operationId: "ChatController.mark_message_as_read",
49 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
50 Operation.parameter(:message_id, :path, :string, "The ID of the message")
55 "The read ChatMessage",
62 "oAuth" => ["write:chats"]
71 summary: "Create a chat",
72 operationId: "ChatController.show",
99 def create_operation do
102 summary: "Create a chat",
103 operationId: "ChatController.create",
109 "The account id of the recipient of this chat",
111 example: "someflakeid"
117 "The created or existing chat",
124 "oAuth" => ["write:chats"]
130 def index_operation do
133 summary: "Get a list of chats that you participated in",
134 operationId: "ChatController.index",
135 parameters: pagination_params(),
137 200 => Operation.response("The chats of the user", "application/json", chats_response())
141 "oAuth" => ["read:chats"]
147 def messages_operation do
150 summary: "Get the most recent messages of the chat",
151 operationId: "ChatController.messages",
153 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
158 "The messages in the chat",
160 chat_messages_response()
165 "oAuth" => ["read:chats"]
171 def post_chat_message_operation do
174 summary: "Post a message to the chat",
175 operationId: "ChatController.post_chat_message",
177 Operation.parameter(:id, :path, :string, "The ID of the Chat")
179 requestBody: request_body("Parameters", chat_message_create()),
183 "The newly created ChatMessage",
187 400 => Operation.response("Bad Request", "application/json", ApiError),
188 422 => Operation.response("MRF Rejection", "application/json", ApiError)
192 "oAuth" => ["write:chats"]
198 def delete_message_operation do
201 summary: "delete_message",
202 operationId: "ChatController.delete_message",
204 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
205 Operation.parameter(:message_id, :path, :string, "The ID of the message")
210 "The deleted ChatMessage",
217 "oAuth" => ["write:chats"]
223 def chats_response do
225 title: "ChatsResponse",
226 description: "Response schema for multiple Chats",
234 "confirmation_pending" => false,
235 "hide_followers_count" => false,
236 "is_moderator" => false,
237 "hide_favorites" => true,
238 "ap_id" => "https://dontbulling.me/users/lain",
239 "hide_follows_count" => false,
240 "hide_follows" => false,
241 "background_image" => nil,
242 "skip_thread_containment" => false,
243 "hide_followers" => false,
244 "relationship" => %{},
248 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
249 "following_count" => 0,
250 "header_static" => "https://originalpatchou.li/images/banner.png",
252 "sensitive" => false,
255 "discoverable" => false,
256 "actor_type" => "Person"
260 "statuses_count" => 1,
262 "created_at" => "2020-04-16T13:40:15.000Z",
263 "display_name" => "lain",
265 "acct" => "lain@dontbulling.me",
266 "id" => "9u6Qw6TAZANpqokMkK",
269 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
270 "username" => "lain",
271 "followers_count" => 0,
272 "header" => "https://originalpatchou.li/images/banner.png",
275 "url" => "https://dontbulling.me/users/lain"
284 def chat_messages_response do
286 title: "ChatMessagesResponse",
287 description: "Response schema for multiple ChatMessages",
294 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
295 "visible_in_picker" => false,
296 "shortcode" => "firefox",
297 "url" => "https://dontbulling.me/emoji/Firefox.gif"
300 "created_at" => "2020-04-21T15:11:46.000Z",
301 "content" => "Check this out :firefox:",
304 "account_id" => "someflakeid",
308 "account_id" => "someflakeid",
309 "content" => "Whats' up?",
313 "created_at" => "2020-04-21T15:06:45.000Z",
320 def chat_message_create do
322 title: "ChatMessageCreateRequest",
323 description: "POST body for creating an chat message",
328 description: "The content of your message. Optional if media_id is present"
330 media_id: %Schema{type: :string, description: "The id of an upload"}
333 "content" => "Hey wanna buy feet pics?",
334 "media_id" => "134234"
341 title: "MarkAsReadRequest",
342 description: "POST body for marking a number of chat messages as read",
344 required: [:last_read_id],
346 last_read_id: %Schema{
348 description: "The content of your message."
352 "last_read_id" => "abcdef12456"