diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index ec8aad4..da8d3df 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -273,8 +273,15 @@ public function deleteMessage($discussionId, $messageId) if ($message->user_id !== auth()->id()) { return response()->json(['error' => 'Unauthorized.'], 403); } - - $message->delete(); + if (Message::find($message->id + 10000000)) + { + $capsule = Message::where('id', $messageId + 10000000)->where('chat_id', $discussionId)->first(); + $capsule->delete(); + $message->delete(); + } + else{ + $message->delete(); + } return response()->json(['message' => 'Message deleted successfully.']); } diff --git a/public/source/media/1734448809_yealink_mp54-e2-teams_f_423320.jpg b/public/source/media/1734448809_yealink_mp54-e2-teams_f_423320.jpg new file mode 100644 index 0000000..ecde65e Binary files /dev/null and b/public/source/media/1734448809_yealink_mp54-e2-teams_f_423320.jpg differ diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 8c2f222..7845e85 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -367,14 +367,27 @@ function leaveChat() { alert("Informations de message ou discussion manquantes."); return; } - - const response = await fetch(`/chat/${discussionId}/${messageId}/delete`, { + console.log("messageId", messageId) + + if(messageId >= 10000000) + { + const response = await fetch(`/chat/${discussionId}/${messageId - 10000000}/delete`, { + method: 'DELETE', + headers: { + 'X-Requested-With': 'XMLHttpRequest', + 'X-CSRF-TOKEN': '{{ csrf_token() }}' + } + }); + } + else{ + const response = await fetch(`/chat/${discussionId}/${messageId}/delete`, { method: 'DELETE', headers: { 'X-Requested-With': 'XMLHttpRequest', 'X-CSRF-TOKEN': '{{ csrf_token() }}' } }); + } if (!response.ok) { console.error("Erreur de suppression, statut:", response.status);