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.Chat
9 alias Pleroma.Web.ApiSpec.Schemas.ChatMessage
11 import Pleroma.Web.ApiSpec.Helpers
13 @spec open_api_operation(atom) :: Operation.t()
14 def open_api_operation(action) do
15 operation = String.to_existing_atom("#{action}_operation")
16 apply(__MODULE__, operation, [])
19 def mark_as_read_operation do
22 summary: "Mark all messages in the chat as read",
23 operationId: "ChatController.mark_as_read",
24 parameters: [Operation.parameter(:id, :path, :string, "The ID of the Chat")],
44 summary: "Create a chat",
45 operationId: "ChatController.show",
72 def create_operation do
75 summary: "Create a chat",
76 operationId: "ChatController.create",
82 "The account id of the recipient of this chat",
84 example: "someflakeid"
90 "The created or existing chat",
103 def index_operation do
106 summary: "Get a list of chats that you participated in",
107 operationId: "ChatController.index",
108 parameters: pagination_params(),
110 200 => Operation.response("The chats of the user", "application/json", chats_response())
120 def messages_operation do
123 summary: "Get the most recent messages of the chat",
124 operationId: "ChatController.messages",
126 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
131 "The messages in the chat",
133 chat_messages_response()
144 def post_chat_message_operation do
147 summary: "Post a message to the chat",
148 operationId: "ChatController.post_chat_message",
150 Operation.parameter(:id, :path, :string, "The ID of the Chat")
152 requestBody: request_body("Parameters", chat_message_create(), required: true),
156 "The newly created ChatMessage",
169 def delete_message_operation do
172 summary: "delete_message",
173 operationId: "ChatController.delete_message",
175 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
176 Operation.parameter(:message_id, :path, :string, "The ID of the message")
181 "The deleted ChatMessage",
194 def chats_response do
196 title: "ChatsResponse",
197 description: "Response schema for multiple Chats",
205 "confirmation_pending" => false,
206 "hide_followers_count" => false,
207 "is_moderator" => false,
208 "hide_favorites" => true,
209 "ap_id" => "https://dontbulling.me/users/lain",
210 "hide_follows_count" => false,
211 "hide_follows" => false,
212 "background_image" => nil,
213 "skip_thread_containment" => false,
214 "hide_followers" => false,
215 "relationship" => %{},
219 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
220 "following_count" => 0,
221 "header_static" => "https://originalpatchou.li/images/banner.png",
223 "sensitive" => false,
226 "discoverable" => false,
227 "actor_type" => "Person"
231 "statuses_count" => 1,
233 "created_at" => "2020-04-16T13:40:15.000Z",
234 "display_name" => "lain",
236 "acct" => "lain@dontbulling.me",
237 "id" => "9u6Qw6TAZANpqokMkK",
240 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
241 "username" => "lain",
242 "followers_count" => 0,
243 "header" => "https://originalpatchou.li/images/banner.png",
246 "url" => "https://dontbulling.me/users/lain"
255 def chat_messages_response do
257 title: "ChatMessagesResponse",
258 description: "Response schema for multiple ChatMessages",
265 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
266 "visible_in_picker" => false,
267 "shortcode" => "firefox",
268 "url" => "https://dontbulling.me/emoji/Firefox.gif"
271 "created_at" => "2020-04-21T15:11:46.000Z",
272 "content" => "Check this out :firefox:",
275 "actor_id" => "someflakeid"
278 "actor_id" => "someflakeid",
279 "content" => "Whats' up?",
283 "created_at" => "2020-04-21T15:06:45.000Z"
289 def chat_message_create do
291 title: "ChatMessageCreateRequest",
292 description: "POST body for creating an chat message",
295 content: %Schema{type: :string, description: "The content of your message"},
296 media_id: %Schema{type: :string, description: "The id of an upload"}
298 required: [:content],
300 "content" => "Hey wanna buy feet pics?",
301 "media_id" => "134234"