Skip to content

Commit

Permalink
Capsul delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Saodus committed Dec 17, 2024
1 parent 9e9ef42 commit aeea7ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
11 changes: 9 additions & 2 deletions app/Http/Controllers/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.']);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit aeea7ce

Please sign in to comment.