wip live chat

- add individual user chat view
- add routes
- wip: action to check and get inbox
This commit is contained in:
kusowl 2026-02-12 12:37:59 +05:30
parent 587893511c
commit a853b58f48
9 changed files with 84 additions and 56 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace App\Actions;
use App\Models\User;
use DB;
final readonly class CreateOrGetInbox
{
/**
* @return array<string, int>
*/
public function execute(User $recipient, User $sender): array
{
$chatExists = DB::table('inbox_user as sender')
->join('inbox_user as recipient', 'sender.inbox_id', '=', 'recipient.inbox_id')
->where('sender.user_id', $sender->id)
->where('recipient.user_id', $recipient->id)
->get();
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Http\Request;
class ChatController extends Controller
{
//
public function index(#[CurrentUser] User $user)
{
return view('dashboards.user.chat') ;
}
public function show(User $recipient)
{
return view('dashboards.user.chat')
->with('recipient', $recipient);
}
}

View File

@ -0,0 +1,14 @@
@props(['recipient', 'chats' => []])
<x-dashboard.page-heading class="m-0 mb-0.5" :title="$recipient->name" description=""/>
<div class="bg-gray-100 h-full overflow-hidden">
<div class="text-sm flex flex-col-reverse overflow-y-scroll h-full max-h-screen pb-50 scroll-snap-y-container">
@forelse($chats as $chat)
<x-chat.message :right="$chat->user_id === auth()->user()->id">{{$chat->text}}</x-chat.message>
@empty
<div class="grid px-4 my-1 w-full h-full place-items-center ">
<p class="text-gray-600">No Messages Found!</p>
</div>
@endforelse
</div>
<x-chat.message-input/>
</div>

View File

@ -1,5 +1,5 @@
@props(['avatar', 'name', 'status' => 'inactive', 'message' => '']) @props(['avatar', 'name', 'status' => 'inactive', 'message' => '', 'link' => ''])
<x-dashboard.broker.sidebar.item class="w-full"> <x-dashboard.broker.sidebar.item :link="$link" class="w-full">
<x-ui.avatar class="w-12! h-12! text-xl!">{{$avatar}}</x-ui.avatar> <x-ui.avatar class="w-12! h-12! text-xl!">{{$avatar}}</x-ui.avatar>
<div class="flex flex-col text-left"> <div class="flex flex-col text-left">
<p class="sidebar-text text-sm font-bold">{{$name}}</p> <p class="sidebar-text text-sm font-bold">{{$name}}</p>

View File

@ -0,0 +1,16 @@
<x-chat.layout>
<x-slot:sidebarItems>
<x-chat.sidebar-item :link="route('chat.show', 8)" name="Kushal Saha" avatar="Ku" message="Hi, how do i do that ?"/>
<x-chat.sidebar-item name="Jhon Doe" avatar="JD" message="How much for thr tv ?"/>
<x-chat.sidebar-item name="Jane Marry" avatar="JM" message="I will let you know"/>
</x-slot:sidebarItems>
@if(isset($recipient))
<x-chat.message-box :recipient="$recipient" />
@else
<div class="w-full h-full flex items-center justify-center">
<p class="font-bold text-5xl text-gray-400">Start a chat ! </p>
</div>
@endif
</x-chat.layout>

View File

@ -1,39 +0,0 @@
<x-chat.layout>
<x-slot:sidebarItems>
<x-chat.sidebar-item name="Kushal Saha" avatar="Ku" message="Hi, how do i do that ?"/>
<x-chat.sidebar-item name="Jhon Doe" avatar="JD" message="How much for thr tv ?"/>
<x-chat.sidebar-item name="Jane Marry" avatar="JM" message="I will let you know"/>
</x-slot:sidebarItems>
<x-dashboard.page-heading class="m-0 mb-0.5" title="Kushal Saha" description="Active now"/>
<div class="bg-gray-100 h-full overflow-hidden">
<div class="text-sm flex flex-col-reverse overflow-y-scroll max-h-screen pb-50 scroll-snap-y-container">
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
<x-chat.message right>Hi</x-chat.message>
<x-chat.message>Hello !</x-chat.message>
</div>
<x-chat.message-input/>
</div>
</x-chat.layout>

View File

@ -10,26 +10,14 @@
require __DIR__.'/web/interaction.php'; require __DIR__.'/web/interaction.php';
require __DIR__.'/web/customer.php'; require __DIR__.'/web/customer.php';
require __DIR__.'/web/admin.php'; require __DIR__.'/web/admin.php';
require __DIR__.'/web/chat.php';
Route::get('/', HomeController::class)->name('home'); Route::get('/', HomeController::class)->name('home');
Route::get('/explore', ExplorePageController::class)->name('explore'); Route::get('/explore', ExplorePageController::class)->name('explore');
Route::post('/contact', ContactController::class)->name('contact'); Route::post('/contact', ContactController::class)->name('contact');
Route::get('/test-openssl', function () {
$res = openssl_pkey_new([
'curve_name' => 'prime256v1',
'private_key_type' => OPENSSL_KEYTYPE_EC,
]);
if ($res === false) {
return 'ERROR: '.openssl_error_string(); // likely "error:02001003:system library:fopen:No such process"
}
return 'SUCCESS: OpenSSL is configured correctly.';
});
/** /**
* This routes are accessed by JS XHR requests, and is loaded here cause * This route is accessed by JS XHR requests, and is loaded here cause
* we do not want to use sanctum for web requests * we do not want to use sanctum for web requests
*/ */
// ------------- API Routes ------------ // ------------- API Routes ------------

6
routes/web/chat.php Normal file
View File

@ -0,0 +1,6 @@
<?php
use App\Http\Controllers\ChatController;
Route::get('/chat', [ChatController::class, 'index'])->name('chat');
Route::get('/chat/{recipient}', [ChatController::class, 'show'])->name('chat.show');

View File

@ -9,5 +9,4 @@
->middleware([HasRole::class.':'.UserTypes::User->value, 'auth']) ->middleware([HasRole::class.':'.UserTypes::User->value, 'auth'])
->group(function () { ->group(function () {
Route::resource('profile', UserProfileController::class)->except('index', 'store', 'create'); Route::resource('profile', UserProfileController::class)->except('index', 'store', 'create');
Route::get('/chat', fn () => view('dashboards.user.chat.index'));
}); });