+ 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)
+ else
+ _e -> {:error, :could_not_delete}
+ end
+ end
+