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
10 alias Pleroma.Web.ApiSpec.Schemas.ChatMessageCreateRequest
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 create_operation do
23 summary: "Create a chat",
24 operationId: "ChatController.create",
30 "The account id of the recipient of this chat",
32 example: "someflakeid"
38 "The created or existing chat",
51 def index_operation do
54 summary: "Get a list of chats that you participated in",
55 operationId: "ChatController.index",
56 parameters: pagination_params(),
58 200 => Operation.response("The chats of the user", "application/json", chats_response())
68 def messages_operation do
71 summary: "Get the most recent messages of the chat",
72 operationId: "ChatController.messages",
74 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
79 "The messages in the chat",
81 chat_messages_response()
92 def post_chat_message_operation do
95 summary: "Post a message to the chat",
96 operationId: "ChatController.post_chat_message",
98 Operation.parameter(:id, :path, :string, "The ID of the Chat")
100 requestBody: request_body("Parameters", ChatMessageCreateRequest, required: true),
104 "The newly created ChatMessage",
117 def chats_response do
119 title: "ChatsResponse",
120 description: "Response schema for multiple Chats",
128 "confirmation_pending" => false,
129 "hide_followers_count" => false,
130 "is_moderator" => false,
131 "hide_favorites" => true,
132 "ap_id" => "https://dontbulling.me/users/lain",
133 "hide_follows_count" => false,
134 "hide_follows" => false,
135 "background_image" => nil,
136 "skip_thread_containment" => false,
137 "hide_followers" => false,
138 "relationship" => %{},
142 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
143 "following_count" => 0,
144 "header_static" => "https://originalpatchou.li/images/banner.png",
146 "sensitive" => false,
149 "discoverable" => false,
150 "actor_type" => "Person"
154 "statuses_count" => 1,
156 "created_at" => "2020-04-16T13:40:15.000Z",
157 "display_name" => "lain",
159 "acct" => "lain@dontbulling.me",
160 "id" => "9u6Qw6TAZANpqokMkK",
163 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
164 "username" => "lain",
165 "followers_count" => 0,
166 "header" => "https://originalpatchou.li/images/banner.png",
169 "url" => "https://dontbulling.me/users/lain"
178 def chat_messages_response do
180 title: "ChatMessagesResponse",
181 description: "Response schema for multiple ChatMessages",
188 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
189 "visible_in_picker" => false,
190 "shortcode" => "firefox",
191 "url" => "https://dontbulling.me/emoji/Firefox.gif"
194 "created_at" => "2020-04-21T15:11:46.000Z",
195 "content" => "Check this out :firefox:",
198 "actor_id" => "someflakeid"
201 "actor_id" => "someflakeid",
202 "content" => "Whats' up?",
206 "created_at" => "2020-04-21T15:06:45.000Z"