Enhance chat functionality: add support for vendor-specific chat channels, implement methods for managing conversations with admin and store owners, and improve conversation payload structure. Update middleware and policies for better access control, and refine chat UI to indicate view-only status for store owner replies.

This commit is contained in:
Mekan1206 committed 2026-08-15 21:17:31 +05:00
1 parent c55694ec8c
commit 5c17c35741
23 files changed
+729 -59

No files matched your search

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('channels', function (Blueprint $table) {
$table->boolean('chatting')->default(false)->after('is_visible');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('chatting');
});
}
};
@@ -0,0 +1,68 @@
<?php
use App\Support\ChatSupport;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('conversations', function (Blueprint $table) {
$table->foreignId('customer_id')->nullable()->after('id')->constrained('users')->nullOnDelete();
$table->foreignId('channel_id')->nullable()->after('customer_id')->constrained('channels')->nullOnDelete();
$table->string('thread_key')->nullable()->after('channel_id');
});
$supportId = ChatSupport::userId();
$claimed = [];
DB::table('conversations')->orderBy('id')->chunkById(100, function ($rows) use ($supportId, &$claimed) {
foreach ($rows as $conversation) {
$userIds = DB::table('conversation_user')
->where('conversation_id', $conversation->id)
->pluck('user_id');
if ($supportId === null || $userIds->count() !== 2 || ! $userIds->contains($supportId)) {
continue;
}
$customerId = (int) $userIds->first(fn ($id) => (int) $id !== $supportId);
$threadKey = 'admin';
if (isset($claimed[$customerId])) {
$threadKey = 'admin-legacy-'.$conversation->id;
} else {
$claimed[$customerId] = true;
}
DB::table('conversations')->where('id', $conversation->id)->update([
'customer_id' => $customerId,
'thread_key' => $threadKey,
]);
}
});
Schema::table('conversations', function (Blueprint $table) {
$table->unique(['customer_id', 'thread_key']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('conversations', function (Blueprint $table) {
$table->dropUnique(['customer_id', 'thread_key']);
$table->dropConstrainedForeignId('channel_id');
$table->dropConstrainedForeignId('customer_id');
$table->dropColumn('thread_key');
});
}
};