Skip to content

Commit

Permalink
message supression for all users in a conv
Browse files Browse the repository at this point in the history
  • Loading branch information
Saodus committed Dec 15, 2024
1 parent ec4167f commit f909718
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
9 changes: 9 additions & 0 deletions app/Http/Controllers/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
36 changes: 28 additions & 8 deletions resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<p class="text-gray-500 italic">Ce message a été supprimé.</p>`;
}
});
})
.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;
Expand Down Expand Up @@ -282,6 +303,5 @@ function deleteMessage(messageId, discussionId) {
});
}
startAutoRefresh();
</script>
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit f909718

Please sign in to comment.