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")],
45 summary: "Create a chat",
46 operationId: "ChatController.show",
73 def create_operation do
76 summary: "Create a chat",
77 operationId: "ChatController.create",
83 "The account id of the recipient of this chat",
85 example: "someflakeid"
91 "The created or existing chat",
104 def index_operation do
107 summary: "Get a list of chats that you participated in",
108 operationId: "ChatController.index",
109 parameters: pagination_params(),
111 200 => Operation.response("The chats of the user", "application/json", chats_response())
121 def messages_operation do
124 summary: "Get the most recent messages of the chat",
125 operationId: "ChatController.messages",
127 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
132 "The messages in the chat",
134 chat_messages_response()
145 def post_chat_message_operation do
148 summary: "Post a message to the chat",
149 operationId: "ChatController.post_chat_message",
151 Operation.parameter(:id, :path, :string, "The ID of the Chat")
153 requestBody: request_body("Parameters", chat_message_create()),
157 "The newly created ChatMessage",
161 400 => Operation.response("Bad Request", "application/json", ApiError)
171 def delete_message_operation do
174 summary: "delete_message",
175 operationId: "ChatController.delete_message",
177 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
178 Operation.parameter(:message_id, :path, :string, "The ID of the message")
183 "The deleted ChatMessage",
196 def chats_response do
198 title: "ChatsResponse",
199 description: "Response schema for multiple Chats",
207 "confirmation_pending" => false,
208 "hide_followers_count" => false,
209 "is_moderator" => false,
210 "hide_favorites" => true,
211 "ap_id" => "https://dontbulling.me/users/lain",
212 "hide_follows_count" => false,
213 "hide_follows" => false,
214 "background_image" => nil,
215 "skip_thread_containment" => false,
216 "hide_followers" => false,
217 "relationship" => %{},
221 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
222 "following_count" => 0,
223 "header_static" => "https://originalpatchou.li/images/banner.png",
225 "sensitive" => false,
228 "discoverable" => false,
229 "actor_type" => "Person"
233 "statuses_count" => 1,
235 "created_at" => "2020-04-16T13:40:15.000Z",
236 "display_name" => "lain",
238 "acct" => "lain@dontbulling.me",
239 "id" => "9u6Qw6TAZANpqokMkK",
242 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
243 "username" => "lain",
244 "followers_count" => 0,
245 "header" => "https://originalpatchou.li/images/banner.png",
248 "url" => "https://dontbulling.me/users/lain"
257 def chat_messages_response do
259 title: "ChatMessagesResponse",
260 description: "Response schema for multiple ChatMessages",
267 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
268 "visible_in_picker" => false,
269 "shortcode" => "firefox",
270 "url" => "https://dontbulling.me/emoji/Firefox.gif"
273 "created_at" => "2020-04-21T15:11:46.000Z",
274 "content" => "Check this out :firefox:",
277 "actor_id" => "someflakeid"
280 "actor_id" => "someflakeid",
281 "content" => "Whats' up?",
285 "created_at" => "2020-04-21T15:06:45.000Z"
291 def chat_message_create do
293 title: "ChatMessageCreateRequest",
294 description: "POST body for creating an chat message",
299 description: "The content of your message. Optional if media_id is present"
301 media_id: %Schema{type: :string, description: "The id of an upload"}
304 "content" => "Hey wanna buy feet pics?",
305 "media_id" => "134234"