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.Helpers
9 alias Pleroma.Web.ApiSpec.Schemas.ChatMessageCreateRequest
10 alias Pleroma.Web.ApiSpec.Schemas.ChatMessageResponse
11 alias Pleroma.Web.ApiSpec.Schemas.ChatResponse
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",
56 Operation.parameter(:limit, :query, :integer, "How many results to return", example: 20),
57 Operation.parameter(:min_id, :query, :string, "Return only chats after this id"),
58 Operation.parameter(:max_id, :query, :string, "Return only chats before this id")
61 200 => Operation.response("The chats of the user", "application/json", chats_response())
71 def messages_operation do
74 summary: "Get the most recent messages of the chat",
75 operationId: "ChatController.messages",
77 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
78 Operation.parameter(:limit, :query, :integer, "How many results to return", example: 20),
79 Operation.parameter(:min_id, :query, :string, "Return only messages after this id"),
80 Operation.parameter(:max_id, :query, :string, "Return only messages before this id")
85 "The messages in the chat",
87 chat_messages_response()
98 def post_chat_message_operation do
101 summary: "Post a message to the chat",
102 operationId: "ChatController.post_chat_message",
104 Operation.parameter(:id, :path, :string, "The ID of the Chat")
106 requestBody: Helpers.request_body("Parameters", ChatMessageCreateRequest, required: true),
110 "The newly created ChatMessage",
123 def chats_response do
125 title: "ChatsResponse",
126 description: "Response schema for multiple Chats",
134 "confirmation_pending" => false,
135 "hide_followers_count" => false,
136 "is_moderator" => false,
137 "hide_favorites" => true,
138 "ap_id" => "https://dontbulling.me/users/lain",
139 "hide_follows_count" => false,
140 "hide_follows" => false,
141 "background_image" => nil,
142 "skip_thread_containment" => false,
143 "hide_followers" => false,
144 "relationship" => %{},
148 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
149 "following_count" => 0,
150 "header_static" => "https://originalpatchou.li/images/banner.png",
152 "sensitive" => false,
155 "discoverable" => false,
156 "actor_type" => "Person"
160 "statuses_count" => 1,
162 "created_at" => "2020-04-16T13:40:15.000Z",
163 "display_name" => "lain",
165 "acct" => "lain@dontbulling.me",
166 "id" => "9u6Qw6TAZANpqokMkK",
169 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
170 "username" => "lain",
171 "followers_count" => 0,
172 "header" => "https://originalpatchou.li/images/banner.png",
175 "url" => "https://dontbulling.me/users/lain"
184 def chat_messages_response do
186 title: "ChatMessagesResponse",
187 description: "Response schema for multiple ChatMessages",
189 items: ChatMessageResponse,
194 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
195 "visible_in_picker" => false,
196 "shortcode" => "firefox",
197 "url" => "https://dontbulling.me/emoji/Firefox.gif"
200 "created_at" => "2020-04-21T15:11:46.000Z",
201 "content" => "Check this out :firefox:",
204 "actor_id" => "someflakeid"
207 "actor_id" => "someflakeid",
208 "content" => "Whats' up?",
212 "created_at" => "2020-04-21T15:06:45.000Z"