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 create_operation do
22 summary: "Create a chat",
23 operationId: "ChatController.create",
29 "The account id of the recipient of this chat",
31 example: "someflakeid"
37 "The created or existing chat",
50 def index_operation do
53 summary: "Get a list of chats that you participated in",
54 operationId: "ChatController.index",
55 parameters: pagination_params(),
57 200 => Operation.response("The chats of the user", "application/json", chats_response())
67 def messages_operation do
70 summary: "Get the most recent messages of the chat",
71 operationId: "ChatController.messages",
73 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
78 "The messages in the chat",
80 chat_messages_response()
91 def post_chat_message_operation do
94 summary: "Post a message to the chat",
95 operationId: "ChatController.post_chat_message",
97 Operation.parameter(:id, :path, :string, "The ID of the Chat")
99 requestBody: request_body("Parameters", chat_message_create(), required: true),
103 "The newly created ChatMessage",
116 def chats_response do
118 title: "ChatsResponse",
119 description: "Response schema for multiple Chats",
127 "confirmation_pending" => false,
128 "hide_followers_count" => false,
129 "is_moderator" => false,
130 "hide_favorites" => true,
131 "ap_id" => "https://dontbulling.me/users/lain",
132 "hide_follows_count" => false,
133 "hide_follows" => false,
134 "background_image" => nil,
135 "skip_thread_containment" => false,
136 "hide_followers" => false,
137 "relationship" => %{},
141 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
142 "following_count" => 0,
143 "header_static" => "https://originalpatchou.li/images/banner.png",
145 "sensitive" => false,
148 "discoverable" => false,
149 "actor_type" => "Person"
153 "statuses_count" => 1,
155 "created_at" => "2020-04-16T13:40:15.000Z",
156 "display_name" => "lain",
158 "acct" => "lain@dontbulling.me",
159 "id" => "9u6Qw6TAZANpqokMkK",
162 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
163 "username" => "lain",
164 "followers_count" => 0,
165 "header" => "https://originalpatchou.li/images/banner.png",
168 "url" => "https://dontbulling.me/users/lain"
177 def chat_messages_response do
179 title: "ChatMessagesResponse",
180 description: "Response schema for multiple ChatMessages",
187 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
188 "visible_in_picker" => false,
189 "shortcode" => "firefox",
190 "url" => "https://dontbulling.me/emoji/Firefox.gif"
193 "created_at" => "2020-04-21T15:11:46.000Z",
194 "content" => "Check this out :firefox:",
197 "actor_id" => "someflakeid"
200 "actor_id" => "someflakeid",
201 "content" => "Whats' up?",
205 "created_at" => "2020-04-21T15:06:45.000Z"
211 def chat_message_create do
213 title: "ChatMessageCreateRequest",
214 description: "POST body for creating an chat message",
217 content: %Schema{type: :string, description: "The content of your message"}
219 required: [:content],
221 "content" => "Hey wanna buy feet pics?"