diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 0a0a6a6..8035277 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -226,4 +226,13 @@ public function deleteMessage($discussionId, $messageId) return response()->json(['message' => 'Message deleted successfully.']); } + + public function getDeletedMessages($chatId) +{ + $deletedMessages = Message::onlyTrashed() + ->where('discussion_id', $chatId) + ->pluck('id'); + + return response()->json(['deletedMessages' => $deletedMessages]); +} } diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index ac2ca53..5cc0a9e 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -177,15 +177,36 @@ class="ml-2 text-red-500 hover:text-red-700 focus:outline-none" .catch(error => console.error('Erreur:', error)) } - // Fonction pour démarrer la mise à jour automatique des messages function startAutoRefresh(intervalTime = 5000) { - if (interval) clearInterval(interval); - interval = setInterval(() => { - if (currentChatId) loadChat(currentChatId, null, null, false); - }, intervalTime); - } + if (interval) clearInterval(interval); + + interval = setInterval(() => { + if (currentChatId) { + loadChat(currentChatId, null, null, false); + + fetch(`/chat/${currentChatId}/deleted-messages`, { + method: 'GET', + headers: { + 'X-Requested-With': 'XMLHttpRequest', + 'X-CSRF-TOKEN': '{{ csrf_token() }}' + } + }) + .then(response => response.json()) + .then(data => { + const deletedMessages = data.deletedMessages || []; + + deletedMessages.forEach(messageId => { + const messageElement = document.getElementById(`message-div-${messageId}`); + if (messageElement) { + messageElement.innerHTML = `
Ce message a été supprimé.
`; + } + }); + }) + .catch(error => console.error('Erreur lors de la récupération des suppressions:', error)); + } + }, intervalTime); +} - // Fonction pour envoyer un message function sendMessage() { const messageContent = document.getElementById('message-content').value; if (!messageContent) return; @@ -282,6 +303,5 @@ function deleteMessage(messageId, discussionId) { }); } - startAutoRefresh(); diff --git a/routes/web.php b/routes/web.php index edd6be5..ef88de9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -25,6 +25,7 @@ Route::post('/chat/{discussion}/capsule', [ChatController::class, 'storeCapsule']); Route::delete('/chat/{discussion}/leave', [ChatController::class, 'leaveChat']); Route::delete('/chat/{discussion}/{message}/delete', [ChatController::class, 'deleteMessage']); + Route::get('/chat/{chatId}/deleted-messages', [ChatController::class, 'getDeletedMessages']); Route::post('/chats', [ChatController::class, 'storeChat'])->name('chats.store'); Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit'); Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');