Add idempotency_key to the chat_message entity.
[akkoma] / lib / pleroma / web / pleroma_api / controllers / chat_controller.ex
index 6357148d012e9f0f0071c03f2e82298919b72e0c..2c4d3f13554388ea2c9bd1d030d9b43de0c1a04f 100644 (file)
@@ -80,7 +80,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
          %User{} = recipient <- User.get_cached_by_ap_id(chat.recipient),
          {:ok, activity} <-
            CommonAPI.post_chat_message(user, recipient, params[:content],
-             media_id: params[:media_id]
+             media_id: params[:media_id],
+             idempotency_key: idempotency_key(conn)
            ),
          message <- Object.normalize(activity, false),
          cm_ref <- MessageReference.for_chat_and_object(chat, message) do
@@ -169,4 +170,11 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
       |> render("show.json", chat: chat)
     end
   end
+
+  defp idempotency_key(conn) do
+    case get_req_header(conn, "idempotency-key") do
+      [key] -> key
+      _ -> nil
+    end
+  end
 end