diff --git a/config/filachat.php b/config/filachat.php index 9fb6815..1f4fb0e 100644 --- a/config/filachat.php +++ b/config/filachat.php @@ -212,6 +212,18 @@ */ 'navigation_icon' => 'heroicon-o-chat-bubble-bottom-center', + /* + |-------------------------------------------------------------------------- + | Navigation Sort + |-------------------------------------------------------------------------- + | + | This option specifies the navigation sort used in the chat navigation. You can + | customize this if you have a different sort order in your application. + | + */ + + 'navigation_sort' => 1, + /* |-------------------------------------------------------------------------- | Max Content Width diff --git a/resources/views/filachat/components/chat-box.blade.php b/resources/views/filachat/components/chat-box.blade.php index 0f9278b..479b57f 100644 --- a/resources/views/filachat/components/chat-box.blade.php +++ b/resources/views/filachat/components/chat-box.blade.php @@ -1,8 +1,8 @@ @props(['selectedConversation'])
+ x-load-css="[@js(\Filament\Support\Facades\FilamentAsset::getStyleHref('filachat-styles', package: 'jaocero/filachat'))]" + class="flex flex-col w-full md:w-2/3 overflow-hidden"> @if ($selectedConversation)
@@ -29,26 +29,54 @@ class="flex flex-col w-full md:w-2/3 overflow-hidden">
-
+ class="flex flex-col-reverse flex-1 p-5 overflow-y-auto"> + +
+ +
+

+ + + + + +

+
+
@foreach ($conversationMessages as $index => $message)
- @php + @php $nextMessage = $conversationMessages[$index + 1] ?? null; $nextMessageDate = $nextMessage ? \Carbon\Carbon::parse($nextMessage->created_at)->setTimezone(config('filachat.timezone', 'app.timezone'))->format('Y-m-d') : null; $currentMessageDate = \Carbon\Carbon::parse($message->created_at)->setTimezone(config('filachat.timezone', 'app.timezone'))->format('Y-m-d'); @@ -75,7 +103,7 @@ class="flex flex-col-reverse flex-1 p-5 overflow-y-auto"> // Show avatar if the current message is the first in a consecutive sequence or a new day $showAvatar = $message->senderable_id !== auth()->user()->id && ($message->senderable_id !== $previousSenderId || $currentMessageDate !== $previousMessageDate); @endphp - +
@if ($showAvatar)
{{__('Loading more messages...')}}
@endif +
@@ -247,18 +276,18 @@ class="flex flex-col-reverse flex-1 p-5 overflow-y-auto">
@script - + + setTimeout(() => { + chatContainer.scrollTop = chatContainer.scrollHeight; + }, 400); + }); + @endscript diff --git a/src/Events/FilaChatUserTypingEvent.php b/src/Events/FilaChatUserTypingEvent.php new file mode 100644 index 0000000..05ad7bf --- /dev/null +++ b/src/Events/FilaChatUserTypingEvent.php @@ -0,0 +1,37 @@ +grow(false), Forms\Components\Textarea::make('message') ->hiddenLabel() + ->live(debounce: 500) + ->afterStateUpdated(function (?string $old, ?string $state) { + // check and set the receiver id + if (auth()->id() === $this->selectedConversation->receiverable_id) { + $receiverableId = $this->selectedConversation->senderable_id; + } else { + $receiverableId = $this->selectedConversation->receiverable_id; + } + // check if the user is typing by comparing the old state and the new state and broadcast the typing event + if ($state != $old) { + broadcast(new FilaChatUserTypingEvent($this->selectedConversation->id, true, $receiverableId)); + } + }) ->placeholder(function () use ($isRoleEnabled, $isAgent, $isOtherPersonAgent) { if ($isRoleEnabled) { diff --git a/src/Pages/FilaChat.php b/src/Pages/FilaChat.php index 9089eea..c894ab2 100644 --- a/src/Pages/FilaChat.php +++ b/src/Pages/FilaChat.php @@ -48,6 +48,11 @@ public static function getNavigationIcon(): string | Htmlable | null return config('filachat.navigation_icon'); } + public static function getNavigationSort(): ?int + { + return config('filachat.navigation_sort'); + } + public function mount(?int $id = null): void { if ($id) {