diff --git a/app/View/Composers/HeaderComposer.php b/app/View/Composers/HeaderComposer.php
index 7bdb43b6..a1b0b4b1 100644
--- a/app/View/Composers/HeaderComposer.php
+++ b/app/View/Composers/HeaderComposer.php
@@ -15,18 +15,25 @@ class HeaderComposer
$userId = auth()->id();
- // Últimas conversaciones con mensajes no leídos
- $unreadConversations = Message::where('receiver_id', $userId)
- ->whereNull('read_at')
+ // Conversaciones donde el último mensaje es del otro usuario (pendiente de respuesta)
+ $pendingConversations = Message::where(function ($q) use ($userId) {
+ $q->where('receiver_id', $userId)
+ ->orWhere('user_id', $userId);
+ })
->with('sender')
->orderBy('created_at', 'desc')
->get()
- ->unique('user_id')
+ ->groupBy(function ($msg) use ($userId) {
+ return $msg->user_id === $userId ? $msg->receiver_id : $msg->user_id;
+ })
+ ->filter(function ($msgs) use ($userId) {
+ return $msgs->first()->user_id !== $userId;
+ })
+ ->map(fn($msgs) => $msgs->first())
->take(5);
- $unreadMessagesCount = Message::where('receiver_id', $userId)
- ->whereNull('read_at')
- ->count();
+ $unreadConversations = $pendingConversations;
+ $unreadMessagesCount = $pendingConversations->count();
// Notificaciones no leídas
$unreadNotifications = auth()->user()
diff --git a/resources/views/chat/show.blade.php b/resources/views/chat/show.blade.php
index 3657ca9c..3acec9ad 100644
--- a/resources/views/chat/show.blade.php
+++ b/resources/views/chat/show.blade.php
@@ -114,6 +114,8 @@ document.getElementById('chat-form').addEventListener('submit', function(e) {
scrollBottom();
form.reset();
document.getElementById('attachment-preview').textContent = '';
+ // Notificar al header que esta conversación ya fue respondida
+ window.dispatchEvent(new CustomEvent('chat:replied', { detail: { receiverId } }));
});
});
diff --git a/resources/views/layouts/_partials/header.blade.php b/resources/views/layouts/_partials/header.blade.php
index 85e1a9be..ab67e4df 100644
--- a/resources/views/layouts/_partials/header.blade.php
+++ b/resources/views/layouts/_partials/header.blade.php
@@ -147,10 +147,10 @@
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ Auth::user()->name }}
- {{-- --}}
-
+ {{--
+ alt="{{ Auth::user()->name }}"> --}}