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 Pleroma.Web.ApiSpec.Helpers
8 alias Pleroma.Web.ApiSpec.Schemas.ChatMessageCreateRequest
9 alias Pleroma.Web.ApiSpec.Schemas.ChatMessageResponse
10 alias Pleroma.Web.ApiSpec.Schemas.ChatResponse
11 alias OpenApiSpex.Schema
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 ActivityPub id of the recipient of this chat.",
31 example: "https://lain.com/users/lain"
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",
131 "recipient" => "https://dontbulling.me/users/lain",
132 "recipient_account" => %{
135 "confirmation_pending" => false,
136 "hide_followers_count" => false,
137 "is_moderator" => false,
138 "hide_favorites" => true,
139 "ap_id" => "https://dontbulling.me/users/lain",
140 "hide_follows_count" => false,
141 "hide_follows" => false,
142 "background_image" => nil,
143 "skip_thread_containment" => false,
144 "hide_followers" => false,
145 "relationship" => %{},
149 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
150 "following_count" => 0,
151 "header_static" => "https://originalpatchou.li/images/banner.png",
153 "sensitive" => false,
156 "discoverable" => false,
157 "actor_type" => "Person"
161 "statuses_count" => 1,
163 "created_at" => "2020-04-16T13:40:15.000Z",
164 "display_name" => "lain",
166 "acct" => "lain@dontbulling.me",
167 "id" => "9u6Qw6TAZANpqokMkK",
170 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
171 "username" => "lain",
172 "followers_count" => 0,
173 "header" => "https://originalpatchou.li/images/banner.png",
176 "url" => "https://dontbulling.me/users/lain"
185 def chat_messages_response() do
187 title: "ChatMessagesResponse",
188 description: "Response schema for multiple ChatMessages",
190 items: ChatMessageResponse,
195 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
196 "visible_in_picker" => false,
197 "shortcode" => "firefox",
198 "url" => "https://dontbulling.me/emoji/Firefox.gif"
201 "created_at" => "2020-04-21T15:11:46.000Z",
202 "content" => "Check this out :firefox:",
205 "actor" => "https://dontbulling.me/users/lain"
208 "actor" => "https://dontbulling.me/users/lain",
209 "content" => "Whats' up?",
213 "created_at" => "2020-04-21T15:06:45.000Z"