Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
[akkoma] / lib / pleroma / web / api_spec / operations / chat_operation.ex
index 0fe0e07b202116d3359389f40ab6cf93a07ccef8..a1c5db5dcd283569592d62a23da78069d9e30470 100644 (file)
@@ -5,6 +5,7 @@
 defmodule Pleroma.Web.ApiSpec.ChatOperation do
   alias OpenApiSpex.Operation
   alias OpenApiSpex.Schema
+  alias Pleroma.Web.ApiSpec.Schemas.ApiError
   alias Pleroma.Web.ApiSpec.Schemas.Chat
   alias Pleroma.Web.ApiSpec.Schemas.ChatMessage
 
@@ -38,6 +39,37 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
     }
   end
 
+  def show_operation do
+    %Operation{
+      tags: ["chat"],
+      summary: "Create a chat",
+      operationId: "ChatController.show",
+      parameters: [
+        Operation.parameter(
+          :id,
+          :path,
+          :string,
+          "The id of the chat",
+          required: true,
+          example: "1234"
+        )
+      ],
+      responses: %{
+        200 =>
+          Operation.response(
+            "The existing chat",
+            "application/json",
+            Chat
+          )
+      },
+      security: [
+        %{
+          "oAuth" => ["read"]
+        }
+      ]
+    }
+  end
+
   def create_operation do
     %Operation{
       tags: ["chat"],
@@ -118,13 +150,39 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
       parameters: [
         Operation.parameter(:id, :path, :string, "The ID of the Chat")
       ],
-      requestBody: request_body("Parameters", chat_message_create(), required: true),
+      requestBody: request_body("Parameters", chat_message_create()),
       responses: %{
         200 =>
           Operation.response(
             "The newly created ChatMessage",
             "application/json",
             ChatMessage
+          ),
+        400 => Operation.response("Bad Request", "application/json", ApiError)
+      },
+      security: [
+        %{
+          "oAuth" => ["write"]
+        }
+      ]
+    }
+  end
+
+  def delete_message_operation do
+    %Operation{
+      tags: ["chat"],
+      summary: "delete_message",
+      operationId: "ChatController.delete_message",
+      parameters: [
+        Operation.parameter(:id, :path, :string, "The ID of the Chat"),
+        Operation.parameter(:message_id, :path, :string, "The ID of the message")
+      ],
+      responses: %{
+        200 =>
+          Operation.response(
+            "The deleted ChatMessage",
+            "application/json",
+            ChatMessage
           )
       },
       security: [
@@ -236,11 +294,15 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
       description: "POST body for creating an chat message",
       type: :object,
       properties: %{
-        content: %Schema{type: :string, description: "The content of your message"}
+        content: %Schema{
+          type: :string,
+          description: "The content of your message. Optional if media_id is present"
+        },
+        media_id: %Schema{type: :string, description: "The id of an upload"}
       },
-      required: [:content],
       example: %{
-        "content" => "Hey wanna buy feet pics?"
+        "content" => "Hey wanna buy feet pics?",
+        "media_id" => "134234"
       }
     }
   end