diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/api_spec/operations/chat_operation.ex | 24 | ||||
-rw-r--r-- | lib/pleroma/web/pleroma_api/controllers/chat_controller.ex | 15 | ||||
-rw-r--r-- | lib/pleroma/web/router.ex | 1 |
3 files changed, 39 insertions, 1 deletions
diff --git a/lib/pleroma/web/api_spec/operations/chat_operation.ex b/lib/pleroma/web/api_spec/operations/chat_operation.ex index 23cb66392..c8f1e2ee7 100644 --- a/lib/pleroma/web/api_spec/operations/chat_operation.ex +++ b/lib/pleroma/web/api_spec/operations/chat_operation.ex @@ -222,6 +222,30 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do } end + def delete_operation do + %Operation{ + tags: ["chat"], + summary: "delete", + operationId: "ChatController.delete", + parameters: [ + Operation.parameter(:id, :path, :string, "The ID of the Chat") + ], + responses: %{ + 200 => + Operation.response( + "The deleted Chat", + "application/json", + Chat + ) + }, + security: [ + %{ + "oAuth" => ["write:chats"] + } + ] + } + end + def delete_message_operation do %Operation{ tags: ["Chats"], diff --git a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex index 669d50132..7d634a154 100644 --- a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex @@ -29,7 +29,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do :create, :mark_as_read, :mark_message_as_read, - :delete_message + :delete_message, + :delete ] ) @@ -42,6 +43,18 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.ChatOperation + def delete(%{assigns: %{user: user}} = conn, %{id: chat_id}) do + with {:ok, chat} <- Chat.get_by_user_and_id(user, chat_id), + {:ok, chat} <- Pleroma.Repo.delete(chat) do + conn + |> put_view(ChatView) + |> render("show.json", chat: chat) + else + _e -> + {:error, :could_not_delete} + end + end + def delete_message(%{assigns: %{user: %{id: user_id} = user}} = conn, %{ message_id: message_id, id: chat_id diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index fa1d1b93f..7aa66248b 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -388,6 +388,7 @@ defmodule Pleroma.Web.Router do post("/chats/by-account-id/:id", ChatController, :create) get("/chats", ChatController, :index) get("/chats/:id", ChatController, :show) + delete("/chats/:id", ChatController, :delete) get("/chats/:id/messages", ChatController, :messages) post("/chats/:id/messages", ChatController, :post_chat_message) delete("/chats/:id/messages/:message_id", ChatController, :delete_message) |