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")],
42 def mark_message_as_read_operation do
45 summary: "Mark one message in the chat as read",
46 operationId: "ChatController.mark_message_as_read",
48 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
49 Operation.parameter(:message_id, :path, :string, "The ID of the message")
54 "The read ChatMessage",
70 summary: "Create a chat",
71 operationId: "ChatController.show",
98 def create_operation do
101 summary: "Create a chat",
102 operationId: "ChatController.create",
108 "The account id of the recipient of this chat",
110 example: "someflakeid"
116 "The created or existing chat",
129 def index_operation do
132 summary: "Get a list of chats that you participated in",
133 operationId: "ChatController.index",
134 parameters: pagination_params(),
136 200 => Operation.response("The chats of the user", "application/json", chats_response())
146 def messages_operation do
149 summary: "Get the most recent messages of the chat",
150 operationId: "ChatController.messages",
152 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
157 "The messages in the chat",
159 chat_messages_response()
170 def post_chat_message_operation do
173 summary: "Post a message to the chat",
174 operationId: "ChatController.post_chat_message",
176 Operation.parameter(:id, :path, :string, "The ID of the Chat")
178 requestBody: request_body("Parameters", chat_message_create()),
182 "The newly created ChatMessage",
186 400 => Operation.response("Bad Request", "application/json", ApiError)
196 def delete_message_operation do
199 summary: "delete_message",
200 operationId: "ChatController.delete_message",
202 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
203 Operation.parameter(:message_id, :path, :string, "The ID of the message")
208 "The deleted ChatMessage",
221 def chats_response do
223 title: "ChatsResponse",
224 description: "Response schema for multiple Chats",
232 "confirmation_pending" => false,
233 "hide_followers_count" => false,
234 "is_moderator" => false,
235 "hide_favorites" => true,
236 "ap_id" => "https://dontbulling.me/users/lain",
237 "hide_follows_count" => false,
238 "hide_follows" => false,
239 "background_image" => nil,
240 "skip_thread_containment" => false,
241 "hide_followers" => false,
242 "relationship" => %{},
246 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
247 "following_count" => 0,
248 "header_static" => "https://originalpatchou.li/images/banner.png",
250 "sensitive" => false,
253 "discoverable" => false,
254 "actor_type" => "Person"
258 "statuses_count" => 1,
260 "created_at" => "2020-04-16T13:40:15.000Z",
261 "display_name" => "lain",
263 "acct" => "lain@dontbulling.me",
264 "id" => "9u6Qw6TAZANpqokMkK",
267 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
268 "username" => "lain",
269 "followers_count" => 0,
270 "header" => "https://originalpatchou.li/images/banner.png",
273 "url" => "https://dontbulling.me/users/lain"
282 def chat_messages_response do
284 title: "ChatMessagesResponse",
285 description: "Response schema for multiple ChatMessages",
292 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
293 "visible_in_picker" => false,
294 "shortcode" => "firefox",
295 "url" => "https://dontbulling.me/emoji/Firefox.gif"
298 "created_at" => "2020-04-21T15:11:46.000Z",
299 "content" => "Check this out :firefox:",
302 "actor_id" => "someflakeid",
306 "actor_id" => "someflakeid",
307 "content" => "Whats' up?",
311 "created_at" => "2020-04-21T15:06:45.000Z",
318 def chat_message_create do
320 title: "ChatMessageCreateRequest",
321 description: "POST body for creating an chat message",
326 description: "The content of your message. Optional if media_id is present"
328 media_id: %Schema{type: :string, description: "The id of an upload"}
331 "content" => "Hey wanna buy feet pics?",
332 "media_id" => "134234"