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 mark_as_read_operation do
22 summary: "Mark all messages in the chat as read",
23 operationId: "ChatController.mark_as_read",
24 parameters: [Operation.parameter(:id, :path, :string, "The ID of the Chat")],
41 def create_operation do
44 summary: "Create a chat",
45 operationId: "ChatController.create",
51 "The account id of the recipient of this chat",
53 example: "someflakeid"
59 "The created or existing chat",
72 def index_operation do
75 summary: "Get a list of chats that you participated in",
76 operationId: "ChatController.index",
77 parameters: pagination_params(),
79 200 => Operation.response("The chats of the user", "application/json", chats_response())
89 def messages_operation do
92 summary: "Get the most recent messages of the chat",
93 operationId: "ChatController.messages",
95 [Operation.parameter(:id, :path, :string, "The ID of the Chat")] ++
100 "The messages in the chat",
102 chat_messages_response()
113 def post_chat_message_operation do
116 summary: "Post a message to the chat",
117 operationId: "ChatController.post_chat_message",
119 Operation.parameter(:id, :path, :string, "The ID of the Chat")
121 requestBody: request_body("Parameters", chat_message_create(), required: true),
125 "The newly created ChatMessage",
138 def chats_response do
140 title: "ChatsResponse",
141 description: "Response schema for multiple Chats",
149 "confirmation_pending" => false,
150 "hide_followers_count" => false,
151 "is_moderator" => false,
152 "hide_favorites" => true,
153 "ap_id" => "https://dontbulling.me/users/lain",
154 "hide_follows_count" => false,
155 "hide_follows" => false,
156 "background_image" => nil,
157 "skip_thread_containment" => false,
158 "hide_followers" => false,
159 "relationship" => %{},
163 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
164 "following_count" => 0,
165 "header_static" => "https://originalpatchou.li/images/banner.png",
167 "sensitive" => false,
170 "discoverable" => false,
171 "actor_type" => "Person"
175 "statuses_count" => 1,
177 "created_at" => "2020-04-16T13:40:15.000Z",
178 "display_name" => "lain",
180 "acct" => "lain@dontbulling.me",
181 "id" => "9u6Qw6TAZANpqokMkK",
184 "https://dontbulling.me/media/065a4dd3c6740dab13ff9c71ec7d240bb9f8be9205c9e7467fb2202117da1e32.jpg",
185 "username" => "lain",
186 "followers_count" => 0,
187 "header" => "https://originalpatchou.li/images/banner.png",
190 "url" => "https://dontbulling.me/users/lain"
199 def chat_messages_response do
201 title: "ChatMessagesResponse",
202 description: "Response schema for multiple ChatMessages",
209 "static_url" => "https://dontbulling.me/emoji/Firefox.gif",
210 "visible_in_picker" => false,
211 "shortcode" => "firefox",
212 "url" => "https://dontbulling.me/emoji/Firefox.gif"
215 "created_at" => "2020-04-21T15:11:46.000Z",
216 "content" => "Check this out :firefox:",
219 "actor_id" => "someflakeid"
222 "actor_id" => "someflakeid",
223 "content" => "Whats' up?",
227 "created_at" => "2020-04-21T15:06:45.000Z"
233 def chat_message_create do
235 title: "ChatMessageCreateRequest",
236 description: "POST body for creating an chat message",
239 content: %Schema{type: :string, description: "The content of your message"},
240 media_id: %Schema{type: :string, description: "The id of an upload"}
242 required: [:content],
244 "content" => "Hey wanna buy feet pics?",
245 "media_id" => "134234"