X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fweb%2Fadmin_api%2Fcontrollers%2Fchat_controller.ex;h=3761a588a98c96024e72570cb59dca8dcd5bcd6f;hb=d04737229196a08db4bc726f8afd55a64dcf8304;hp=ac362c430f3034cdb128a4a09b50e918e62e226a;hpb=9dd0b23da424c380a37897d8bf69ab241efa6f91;p=akkoma
diff --git a/lib/pleroma/web/admin_api/controllers/chat_controller.ex b/lib/pleroma/web/admin_api/controllers/chat_controller.ex
index ac362c430..3761a588a 100644
--- a/lib/pleroma/web/admin_api/controllers/chat_controller.ex
+++ b/lib/pleroma/web/admin_api/controllers/chat_controller.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.ChatController do
@@ -10,10 +10,10 @@ defmodule Pleroma.Web.AdminAPI.ChatController do
alias Pleroma.Chat.MessageReference
alias Pleroma.ModerationLog
alias Pleroma.Pagination
- alias Pleroma.Plugs.OAuthScopesPlug
+ alias Pleroma.Web.AdminAPI
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView
- alias Pleroma.Web.PleromaAPI.ChatView
+ alias Pleroma.Web.Plugs.OAuthScopesPlug
require Logger
@@ -33,15 +33,27 @@ defmodule Pleroma.Web.AdminAPI.ChatController do
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.ChatOperation
- def delete_message(%{assigns: %{user: user}} = conn, %{message_id: id}) do
- with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
+ def delete_message(%{assigns: %{user: user}} = conn, %{
+ message_id: message_id,
+ id: chat_id
+ }) do
+ with %MessageReference{object: %{data: %{"id" => object_ap_id}}} = cm_ref <-
+ MessageReference.get_by_id(message_id),
+ ^chat_id <- to_string(cm_ref.chat_id),
+ %Activity{id: activity_id} <- Activity.get_create_by_object_ap_id(object_ap_id),
+ {:ok, _} <- CommonAPI.delete(activity_id, user) do
ModerationLog.insert_log(%{
action: "chat_message_delete",
actor: user,
- subject_id: id
+ subject_id: message_id
})
- json(conn, %{})
+ conn
+ |> put_view(MessageReferenceView)
+ |> render("show.json", chat_message_reference: cm_ref)
+ else
+ _e ->
+ {:error, :could_not_delete}
end
end
@@ -66,7 +78,7 @@ defmodule Pleroma.Web.AdminAPI.ChatController do
def show(conn, %{id: id}) do
with %Chat{} = chat <- Chat.get_by_id(id) do
conn
- |> put_view(ChatView)
+ |> put_view(AdminAPI.ChatView)
|> render("show.json", chat: chat)
end
end