diff options
author | lain <lain@soykaf.club> | 2020-05-12 13:13:03 +0200 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-05-12 13:13:03 +0200 |
commit | b5aa204eb8bf3f737d3d807a9924c0153d1b6d3e (patch) | |
tree | 0ebbe58181b58eb18d466f02e98a2e7726c6d8d7 /lib/pleroma/web/pleroma_api/controllers/chat_controller.ex | |
parent | f28ed36b4daf2f7ed2e35b90b07a5b0552b2a2c9 (diff) | |
download | pleroma-b5aa204eb8bf3f737d3d807a9924c0153d1b6d3e.tar.gz |
ChatController: Support deletion of chat messages.
Diffstat (limited to 'lib/pleroma/web/pleroma_api/controllers/chat_controller.ex')
-rw-r--r-- | lib/pleroma/web/pleroma_api/controllers/chat_controller.ex | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex index 04f136dcd..8eed88752 100644 --- a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex @@ -4,6 +4,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do use Pleroma.Web, :controller + alias Pleroma.Activity alias Pleroma.Chat alias Pleroma.Object alias Pleroma.Pagination @@ -22,7 +23,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do plug( OAuthScopesPlug, - %{scopes: ["write:statuses"]} when action in [:post_chat_message, :create, :mark_as_read] + %{scopes: ["write:statuses"]} + when action in [:post_chat_message, :create, :mark_as_read, :delete_message] ) plug( @@ -34,6 +36,26 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.ChatOperation + def delete_message(%{assigns: %{user: %{ap_id: actor} = user}} = conn, %{ + message_id: id + }) do + with %Object{ + data: %{ + "actor" => ^actor, + "id" => object, + "to" => [recipient], + "type" => "ChatMessage" + } + } = message <- Object.get_by_id(id), + %Chat{} = chat <- Chat.get(user.id, recipient), + %Activity{} = activity <- Activity.get_create_by_object_ap_id(object), + {:ok, _delete} <- CommonAPI.delete(activity.id, user) do + conn + |> put_view(ChatMessageView) + |> render("show.json", for: user, object: message, chat: chat) + end + end + def post_chat_message( %{body_params: %{content: content} = params, assigns: %{user: %{id: user_id} = user}} = conn, |