diff --git a/app/Http/Livewire/Chat/PublicChat.php b/app/Http/Livewire/Chat/PublicChat.php index e5eb28f..ac0f144 100755 --- a/app/Http/Livewire/Chat/PublicChat.php +++ b/app/Http/Livewire/Chat/PublicChat.php @@ -63,16 +63,13 @@ class PublicChat extends Component public function mount(): void { $userId = session('chat_user_id'); - $convId = session('chat_conv_id'); - if (! $userId || ! $convId) { + if (! $userId) { return; } $user = User::with('saldo')->find($userId); - $conv = ChatConversation::find($convId); - - if (! $user || ! $conv) { + if (! $user) { session()->forget(['chat_user_id', 'chat_conv_id']); return; } @@ -80,10 +77,19 @@ class PublicChat extends Component $this->userId = $user->id; $this->nombreUsuario = $user->name; $this->saldoUsuario = $user->saldo?->valor ?? 0; - $this->convId = $conv->id; - $this->estadoConv = $conv->estado; $this->paso = 'chat'; - $this->cargarMensajes(); + + $convId = session('chat_conv_id'); + if ($convId) { + $conv = ChatConversation::find($convId); + if ($conv) { + $this->convId = $conv->id; + $this->estadoConv = $conv->estado; + $this->cargarMensajes(); + } else { + session()->forget('chat_conv_id'); + } + } } protected $rules = [ @@ -193,12 +199,13 @@ class PublicChat extends Component public function limpiarChat(): void { - // Cierra la conversación actual y abre una nueva en la próxima interacción - $this->mensajes = []; - $this->convId = null; - $this->flujo = ''; - $this->flujoData = []; + $this->mensajes = []; + $this->convId = null; + $this->flujo = ''; + $this->flujoData = []; + $this->estadoConv = 'bot'; session()->forget('chat_conv_id'); + // paso, userId, nombreUsuario, saldoUsuario se mantienen — sesión intacta } public function cerrarSesion(): void