Compare commits
No commits in common. "master" and "feature/defensive-mutation-constraints" have entirely different histories.
master
...
feature/de
5
.gitignore
vendored
5
.gitignore
vendored
@ -28,7 +28,4 @@ yarn-error.log
|
|||||||
/.vscode
|
/.vscode
|
||||||
/.zed
|
/.zed
|
||||||
/public/sw.js
|
/public/sw.js
|
||||||
/public/workbox-*.js
|
/public/workbox-*.js
|
||||||
/tests/Browser/console
|
|
||||||
/tests/Browser/screenshots
|
|
||||||
/tests/Browser/source
|
|
||||||
@ -19,7 +19,6 @@ This application is a Laravel application and its main Laravel ecosystems packag
|
|||||||
- tightenco/ziggy (ZIGGY) - v2
|
- tightenco/ziggy (ZIGGY) - v2
|
||||||
- larastan/larastan (LARASTAN) - v3
|
- larastan/larastan (LARASTAN) - v3
|
||||||
- laravel/boost (BOOST) - v2
|
- laravel/boost (BOOST) - v2
|
||||||
- laravel/dusk (DUSK) - v8
|
|
||||||
- laravel/mcp (MCP) - v0
|
- laravel/mcp (MCP) - v0
|
||||||
- laravel/pail (PAIL) - v1
|
- laravel/pail (PAIL) - v1
|
||||||
- laravel/pint (PINT) - v1
|
- laravel/pint (PINT) - v1
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Concerns;
|
|
||||||
|
|
||||||
trait SerializesIdToUuid
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Convert the model's attributes to an array.
|
|
||||||
* Overrides the default model toArray method to replace 'id' with 'uuid'.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function toArray(): array
|
|
||||||
{
|
|
||||||
$array = parent::toArray();
|
|
||||||
|
|
||||||
if (isset($this->uuid)) {
|
|
||||||
$array['id'] = $this->uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $array;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -11,10 +11,10 @@ class DashboardController extends Controller
|
|||||||
public function index(Request $request, ActivityService $activityService)
|
public function index(Request $request, ActivityService $activityService)
|
||||||
{
|
{
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$unreadEntities = $activityService->getUnreadEntitiesGrouped($user);
|
$unreadDynamics = $activityService->getUnreadDynamicsGrouped($user);
|
||||||
|
|
||||||
return Inertia::render('Dashboard', [
|
return Inertia::render('Dashboard', [
|
||||||
'unreadEntities' => $unreadEntities,
|
'unreadDynamics' => $unreadDynamics,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,10 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Requests\UpdateDynamicRequest;
|
use App\Http\Requests\UpdateDynamicRequest;
|
||||||
|
use App\Http\Resources\DynamicResource;
|
||||||
|
use App\Http\Resources\LedgerResource;
|
||||||
|
use App\Http\Resources\MessageResource;
|
||||||
|
use App\Http\Resources\UserResource;
|
||||||
use App\Models\Dynamic;
|
use App\Models\Dynamic;
|
||||||
use App\Services\ActivityService;
|
use App\Services\ActivityService;
|
||||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||||
@ -19,7 +23,7 @@ class DynamicController extends Controller
|
|||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
return Inertia::render('Dynamics/Index', [
|
return Inertia::render('Dynamics/Index', [
|
||||||
'dynamics' => $request->user()->dynamics()->get(),
|
'dynamics' => DynamicResource::collection($request->user()->dynamics()->get()),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,10 +59,10 @@ class DynamicController extends Controller
|
|||||||
$dynamic->load(['ledgers.media', 'participants', 'chat']);
|
$dynamic->load(['ledgers.media', 'participants', 'chat']);
|
||||||
|
|
||||||
return Inertia::render('Dynamics/Show', [
|
return Inertia::render('Dynamics/Show', [
|
||||||
'dynamic' => $dynamic,
|
'dynamic' => new DynamicResource($dynamic),
|
||||||
'ledgers' => $dynamic->ledgers,
|
'ledgers' => LedgerResource::collection($dynamic->ledgers),
|
||||||
'participants' => $dynamic->participants,
|
'participants' => UserResource::collection($dynamic->participants),
|
||||||
'messages' => $dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT),
|
'messages' => MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT)),
|
||||||
'can' => [
|
'can' => [
|
||||||
'update' => $request->user()->can('update', $dynamic),
|
'update' => $request->user()->can('update', $dynamic),
|
||||||
],
|
],
|
||||||
@ -69,7 +73,7 @@ class DynamicController extends Controller
|
|||||||
{
|
{
|
||||||
$this->authorize('view', $dynamic);
|
$this->authorize('view', $dynamic);
|
||||||
|
|
||||||
return $dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT);
|
return MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,7 +84,7 @@ class DynamicController extends Controller
|
|||||||
$this->authorize('update', $dynamic);
|
$this->authorize('update', $dynamic);
|
||||||
|
|
||||||
return Inertia::render('Dynamics/Settings', [
|
return Inertia::render('Dynamics/Settings', [
|
||||||
'dynamic' => $dynamic,
|
'dynamic' => new DynamicResource($dynamic),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,11 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Requests\StoreLedgerRequest;
|
use App\Http\Requests\StoreLedgerRequest;
|
||||||
|
use App\Http\Resources\DynamicResource;
|
||||||
|
use App\Http\Resources\LedgerResource;
|
||||||
|
use App\Http\Resources\MessageResource;
|
||||||
|
use App\Http\Resources\MutationResource;
|
||||||
|
use App\Http\Resources\UserResource;
|
||||||
use App\Models\Dynamic;
|
use App\Models\Dynamic;
|
||||||
use App\Models\Ledger;
|
use App\Models\Ledger;
|
||||||
use App\Services\ActivityService;
|
use App\Services\ActivityService;
|
||||||
@ -30,7 +35,7 @@ class LedgerController extends Controller
|
|||||||
$this->authorize('update', $dynamic);
|
$this->authorize('update', $dynamic);
|
||||||
|
|
||||||
return Inertia::render('Ledgers/Create', [
|
return Inertia::render('Ledgers/Create', [
|
||||||
'dynamic' => $dynamic,
|
'dynamic' => new DynamicResource($dynamic),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,9 +83,11 @@ class LedgerController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return Inertia::render('Ledgers/Show', [
|
return Inertia::render('Ledgers/Show', [
|
||||||
'dynamic' => $dynamic,
|
'dynamic' => new DynamicResource($dynamic),
|
||||||
'ledger' => $ledger,
|
'ledger' => new LedgerResource($ledger),
|
||||||
'messages' => $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT),
|
'mutations' => MutationResource::collection($ledger->mutations),
|
||||||
|
'participants' => UserResource::collection($dynamic->participants),
|
||||||
|
'messages' => MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT)),
|
||||||
'can' => [
|
'can' => [
|
||||||
'update' => $request->user()->can('update', $ledger),
|
'update' => $request->user()->can('update', $ledger),
|
||||||
'close' => $request->user()->can('close', $ledger),
|
'close' => $request->user()->can('close', $ledger),
|
||||||
@ -92,7 +99,7 @@ class LedgerController extends Controller
|
|||||||
{
|
{
|
||||||
$this->authorize('view', $ledger);
|
$this->authorize('view', $ledger);
|
||||||
|
|
||||||
return $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT);
|
return MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,8 +110,8 @@ class LedgerController extends Controller
|
|||||||
$this->authorize('update', $ledger);
|
$this->authorize('update', $ledger);
|
||||||
|
|
||||||
return Inertia::render('Ledgers/Edit', [
|
return Inertia::render('Ledgers/Edit', [
|
||||||
'dynamic' => $dynamic,
|
'dynamic' => new DynamicResource($dynamic),
|
||||||
'ledger' => $ledger,
|
'ledger' => new LedgerResource($ledger),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ use App\Events\MessageSent;
|
|||||||
use App\Events\MutationCreated;
|
use App\Events\MutationCreated;
|
||||||
use App\Events\MutationUpdated;
|
use App\Events\MutationUpdated;
|
||||||
use App\Http\Requests\StoreMutationRequest;
|
use App\Http\Requests\StoreMutationRequest;
|
||||||
|
use App\Http\Resources\MutationResource;
|
||||||
use App\Models\Dynamic;
|
use App\Models\Dynamic;
|
||||||
use App\Models\Ledger;
|
use App\Models\Ledger;
|
||||||
use App\Models\Mutation;
|
use App\Models\Mutation;
|
||||||
@ -70,6 +71,9 @@ class MutationController extends Controller
|
|||||||
return $mutation;
|
return $mutation;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Broadcast the real-time creation event!
|
||||||
|
broadcast(new MutationCreated($mutation));
|
||||||
|
|
||||||
return redirect()->route('dynamics.ledgers.show', [$dynamic, $ledger]);
|
return redirect()->route('dynamics.ledgers.show', [$dynamic, $ledger]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +84,7 @@ class MutationController extends Controller
|
|||||||
{
|
{
|
||||||
$this->authorize('view', $mutation);
|
$this->authorize('view', $mutation);
|
||||||
|
|
||||||
return $mutation;
|
return new MutationResource($mutation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,6 +149,9 @@ class MutationController extends Controller
|
|||||||
}
|
}
|
||||||
broadcast(new MessageSent($dynamicMsg));
|
broadcast(new MessageSent($dynamicMsg));
|
||||||
|
|
||||||
|
// Broadcast the real-time update event!
|
||||||
|
broadcast(new MutationUpdated($mutation));
|
||||||
|
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,7 @@ class ParticipantController extends Controller
|
|||||||
return Inertia::render('Dynamics/Participants/Show', [
|
return Inertia::render('Dynamics/Participants/Show', [
|
||||||
'dynamic' => $dynamic,
|
'dynamic' => $dynamic,
|
||||||
'participant' => [
|
'participant' => [
|
||||||
'id' => $user->uuid,
|
'id' => $user->id,
|
||||||
'name' => $user->name,
|
'name' => $user->name,
|
||||||
'display_name' => $participant->pivot->display_name,
|
'display_name' => $participant->pivot->display_name,
|
||||||
'role' => $participant->pivot->role,
|
'role' => $participant->pivot->role,
|
||||||
|
|||||||
@ -50,7 +50,7 @@ class HandleInertiaRequests extends Middleware
|
|||||||
|
|
||||||
$service = app(ActivityService::class);
|
$service = app(ActivityService::class);
|
||||||
|
|
||||||
return count($service->getUnreadEntitiesGrouped($request->user()));
|
return count($service->getUnreadDynamicsGrouped($request->user()));
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
25
app/Http/Resources/BaseResource.php
Normal file
25
app/Http/Resources/BaseResource.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class BaseResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
$data = parent::toArray($request);
|
||||||
|
|
||||||
|
if (isset($data['id']) && isset($this->uuid)) {
|
||||||
|
$data['id'] = $this->uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/Http/Resources/DynamicResource.php
Normal file
25
app/Http/Resources/DynamicResource.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class DynamicResource extends BaseResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
$result = parent::toArray($request);
|
||||||
|
if ($this->ledgers) {
|
||||||
|
$result['ledgers'] = LedgerResource::collection($this->ledgers);
|
||||||
|
}
|
||||||
|
if ($this->participants) {
|
||||||
|
$result['participants'] = ParticipantResource::collection($this->participants);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Http/Resources/LedgerResource.php
Normal file
18
app/Http/Resources/LedgerResource.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class LedgerResource extends BaseResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return parent::toArray($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Http/Resources/MessageResource.php
Normal file
18
app/Http/Resources/MessageResource.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class MessageResource extends BaseResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return parent::toArray($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/Http/Resources/MutationResource.php
Normal file
25
app/Http/Resources/MutationResource.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class MutationResource extends BaseResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
$data = parent::toArray($request);
|
||||||
|
|
||||||
|
$data['can'] = [
|
||||||
|
'update' => $request->user()?->can('update', $this->resource) ?? false,
|
||||||
|
'void' => $request->user()?->can('void', $this->resource) ?? false,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Http/Resources/ParticipantResource.php
Normal file
18
app/Http/Resources/ParticipantResource.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class ParticipantResource extends BaseResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return parent::toArray($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Http/Resources/PredefinedMutationResource.php
Normal file
18
app/Http/Resources/PredefinedMutationResource.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class PredefinedMutationResource extends BaseResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return parent::toArray($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Http/Resources/UserResource.php
Normal file
18
app/Http/Resources/UserResource.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class UserResource extends BaseResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return parent::toArray($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,13 +9,11 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use App\Models\Chat;
|
|
||||||
use App\Concerns\SerializesIdToUuid;
|
|
||||||
|
|
||||||
class Dynamic extends Model
|
class Dynamic extends Model
|
||||||
{
|
{
|
||||||
/** @use HasFactory<DynamicFactory> */
|
/** @use HasFactory<DynamicFactory> */
|
||||||
use HasFactory, SerializesIdToUuid;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
@ -66,13 +64,4 @@ class Dynamic extends Model
|
|||||||
public function getUrlAttribute(): string {
|
public function getUrlAttribute(): string {
|
||||||
return route('dynamics.show', $this);
|
return route('dynamics.show', $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrCreateChat(): Chat
|
|
||||||
{
|
|
||||||
if ($this->chat) {
|
|
||||||
return $this->chat;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->chat()->create([]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,12 +9,11 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use App\Concerns\SerializesIdToUuid;
|
|
||||||
|
|
||||||
class Ledger extends Model
|
class Ledger extends Model
|
||||||
{
|
{
|
||||||
/** @use HasFactory<LedgerFactory> */
|
/** @use HasFactory<LedgerFactory> */
|
||||||
use HasFactory, SerializesIdToUuid;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'dynamic_id',
|
'dynamic_id',
|
||||||
|
|||||||
@ -10,12 +10,11 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use App\Concerns\SerializesIdToUuid;
|
|
||||||
|
|
||||||
class Mutation extends Model
|
class Mutation extends Model
|
||||||
{
|
{
|
||||||
/** @use HasFactory<MutationFactory> */
|
/** @use HasFactory<MutationFactory> */
|
||||||
use HasFactory, SerializesIdToUuid;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'ledger_id',
|
'ledger_id',
|
||||||
@ -93,26 +92,7 @@ class Mutation extends Model
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
broadcast(new MessageSent($dynamicMsg));
|
broadcast(new MessageSent($dynamicMsg));
|
||||||
|
|
||||||
// Trigger the real-time creation broadcast dynamically
|
|
||||||
broadcast(new \App\Events\MutationCreated($mutation));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
static::updated(function (Mutation $mutation) {
|
|
||||||
if ($mutation->wasChanged('status')) {
|
|
||||||
broadcast(new \App\Events\MutationUpdated($mutation));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected $appends = ['can'];
|
|
||||||
|
|
||||||
public function getCanAttribute(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'update' => auth()->user()?->can('update', $this) ?? false,
|
|
||||||
'void' => auth()->user()?->can('void', $this) ?? false,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRouteKeyName()
|
public function getRouteKeyName()
|
||||||
|
|||||||
@ -6,11 +6,10 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use App\Concerns\SerializesIdToUuid;
|
|
||||||
|
|
||||||
class PredefinedMutation extends Model
|
class PredefinedMutation extends Model
|
||||||
{
|
{
|
||||||
use HasFactory, SerializesIdToUuid;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'ledger_id',
|
'ledger_id',
|
||||||
|
|||||||
@ -15,7 +15,6 @@ use Laravel\Fortify\Contracts\PasskeyUser;
|
|||||||
use Laravel\Fortify\PasskeyAuthenticatable;
|
use Laravel\Fortify\PasskeyAuthenticatable;
|
||||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||||
use NotificationChannels\WebPush\HasPushSubscriptions;
|
use NotificationChannels\WebPush\HasPushSubscriptions;
|
||||||
use App\Concerns\SerializesIdToUuid;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
@ -35,7 +34,7 @@ use App\Concerns\SerializesIdToUuid;
|
|||||||
class User extends Authenticatable implements PasskeyUser
|
class User extends Authenticatable implements PasskeyUser
|
||||||
{
|
{
|
||||||
/** @use HasFactory<UserFactory> */
|
/** @use HasFactory<UserFactory> */
|
||||||
use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable, SerializesIdToUuid;
|
use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable;
|
||||||
|
|
||||||
public function dynamics()
|
public function dynamics()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
use Illuminate\Support\Facades\Date;
|
use Illuminate\Support\Facades\Date;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@ -27,13 +26,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
JsonResource::withoutWrapping();
|
JsonResource::withoutWrapping();
|
||||||
$this->configureDefaults();
|
$this->configureDefaults();
|
||||||
|
|
||||||
Relation::morphMap([
|
|
||||||
'user' => \App\Models\User::class,
|
|
||||||
'dynamic' => \App\Models\Dynamic::class,
|
|
||||||
'ledger' => \App\Models\Ledger::class,
|
|
||||||
'mutation' => \App\Models\Mutation::class,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -45,9 +45,8 @@ class ActivityService
|
|||||||
return $cursor ? $cursor->read_at : Carbon::parse('1970-01-01');
|
return $cursor ? $cursor->read_at : Carbon::parse('1970-01-01');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createMessage($dynamic, $user, $content, $subject = null)
|
public function createMessage($chat, $user, $content, $subject = null)
|
||||||
{
|
{
|
||||||
$chat = $dynamic->getOrCreateChat();
|
|
||||||
$message = $chat->messages()->create([
|
$message = $chat->messages()->create([
|
||||||
'user_id' => $user ? $user->id : null,
|
'user_id' => $user ? $user->id : null,
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
@ -93,11 +92,6 @@ class ActivityService
|
|||||||
*/
|
*/
|
||||||
public function getActivitiesForDynamic(Dynamic $dynamic): array
|
public function getActivitiesForDynamic(Dynamic $dynamic): array
|
||||||
{
|
{
|
||||||
$chat = $dynamic->getOrCreateChat();
|
|
||||||
if (!$chat) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$participants = $dynamic->participants()->withPivot('display_name')->get();
|
$participants = $dynamic->participants()->withPivot('display_name')->get();
|
||||||
$participantsMap = $participants->reduce(function ($acc, $p) {
|
$participantsMap = $participants->reduce(function ($acc, $p) {
|
||||||
$acc[$p->id] = $p->pivot->display_name ?? $p->name;
|
$acc[$p->id] = $p->pivot->display_name ?? $p->name;
|
||||||
@ -105,7 +99,7 @@ class ActivityService
|
|||||||
return $acc;
|
return $acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
$messages = Message::where('chat_id', $chat->id)
|
$messages = Message::where('chat_id', $dynamic->chat->id)
|
||||||
->with(['user', 'subject'])
|
->with(['user', 'subject'])
|
||||||
->latest()
|
->latest()
|
||||||
->get();
|
->get();
|
||||||
@ -128,10 +122,10 @@ class ActivityService
|
|||||||
/**
|
/**
|
||||||
* Get unread activities grouped by active entities (Dynamics, Ledgers) for the given user.
|
* Get unread activities grouped by active entities (Dynamics, Ledgers) for the given user.
|
||||||
*/
|
*/
|
||||||
public function getUnreadEntitiesGrouped(User $user): array
|
public function getUnreadDynamicsGrouped(User $user): array
|
||||||
{
|
{
|
||||||
$groupedDynamics = [];
|
$groupedDynamics = [];
|
||||||
$participatingDynamics = $user->dynamics()->with(['chat', 'ledgers'])->get();
|
$participatingDynamics = $user->dynamics()->with('ledgers')->get();
|
||||||
|
|
||||||
foreach ($participatingDynamics as $dynamic) {
|
foreach ($participatingDynamics as $dynamic) {
|
||||||
$readAt = $this->getCursorReadAt($user, $dynamic);
|
$readAt = $this->getCursorReadAt($user, $dynamic);
|
||||||
|
|||||||
@ -24,7 +24,6 @@
|
|||||||
"fakerphp/faker": "^1.24",
|
"fakerphp/faker": "^1.24",
|
||||||
"larastan/larastan": "^3.9",
|
"larastan/larastan": "^3.9",
|
||||||
"laravel/boost": "^2.2",
|
"laravel/boost": "^2.2",
|
||||||
"laravel/dusk": "^8.6",
|
|
||||||
"laravel/pail": "^1.2.5",
|
"laravel/pail": "^1.2.5",
|
||||||
"laravel/pao": "^1.0.6",
|
"laravel/pao": "^1.0.6",
|
||||||
"laravel/pint": "^1.27",
|
"laravel/pint": "^1.27",
|
||||||
|
|||||||
142
composer.lock
generated
142
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "26618424deaf53a19e8fe992032eef9c",
|
"content-hash": "f4c79dcf0b7f9f54487404715d1085c1",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "bacon/bacon-qr-code",
|
"name": "bacon/bacon-qr-code",
|
||||||
@ -9714,80 +9714,6 @@
|
|||||||
},
|
},
|
||||||
"time": "2026-06-09T10:21:08+00:00"
|
"time": "2026-06-09T10:21:08+00:00"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "laravel/dusk",
|
|
||||||
"version": "v8.6.0",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/laravel/dusk.git",
|
|
||||||
"reference": "e7fd48762c6a82ad2cd311db07587aa2a97ce143"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/laravel/dusk/zipball/e7fd48762c6a82ad2cd311db07587aa2a97ce143",
|
|
||||||
"reference": "e7fd48762c6a82ad2cd311db07587aa2a97ce143",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"ext-json": "*",
|
|
||||||
"ext-zip": "*",
|
|
||||||
"guzzlehttp/guzzle": "^7.5",
|
|
||||||
"illuminate/console": "^10.0|^11.0|^12.0|^13.0",
|
|
||||||
"illuminate/support": "^10.0|^11.0|^12.0|^13.0",
|
|
||||||
"php": "^8.1",
|
|
||||||
"php-webdriver/webdriver": "^1.15.2",
|
|
||||||
"symfony/console": "^6.2|^7.0|^8.0",
|
|
||||||
"symfony/finder": "^6.2|^7.0|^8.0",
|
|
||||||
"symfony/process": "^6.2|^7.0|^8.0",
|
|
||||||
"vlucas/phpdotenv": "^5.2"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"laravel/framework": "^10.0|^11.0|^12.0|^13.0",
|
|
||||||
"mockery/mockery": "^1.6",
|
|
||||||
"orchestra/testbench-core": "^8.19|^9.17|^10.8|^11.0",
|
|
||||||
"phpstan/phpstan": "^1.10",
|
|
||||||
"phpunit/phpunit": "^10.1|^11.0|^12.0.1",
|
|
||||||
"psy/psysh": "^0.11.12|^0.12",
|
|
||||||
"symfony/yaml": "^6.2|^7.0|^8.0"
|
|
||||||
},
|
|
||||||
"suggest": {
|
|
||||||
"ext-pcntl": "Used to gracefully terminate Dusk when tests are running."
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"extra": {
|
|
||||||
"laravel": {
|
|
||||||
"providers": [
|
|
||||||
"Laravel\\Dusk\\DuskServiceProvider"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Laravel\\Dusk\\": "src/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Taylor Otwell",
|
|
||||||
"email": "taylor@laravel.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Laravel Dusk provides simple end-to-end testing and browser automation.",
|
|
||||||
"keywords": [
|
|
||||||
"laravel",
|
|
||||||
"testing",
|
|
||||||
"webdriver"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/laravel/dusk/issues",
|
|
||||||
"source": "https://github.com/laravel/dusk/tree/v8.6.0"
|
|
||||||
},
|
|
||||||
"time": "2026-04-15T14:50:40+00:00"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "laravel/mcp",
|
"name": "laravel/mcp",
|
||||||
"version": "v0.8.1",
|
"version": "v0.8.1",
|
||||||
@ -11041,72 +10967,6 @@
|
|||||||
},
|
},
|
||||||
"time": "2022-02-21T01:04:05+00:00"
|
"time": "2022-02-21T01:04:05+00:00"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "php-webdriver/webdriver",
|
|
||||||
"version": "1.16.0",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/php-webdriver/php-webdriver.git",
|
|
||||||
"reference": "ac0662863aa120b4f645869f584013e4c4dba46a"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/php-webdriver/php-webdriver/zipball/ac0662863aa120b4f645869f584013e4c4dba46a",
|
|
||||||
"reference": "ac0662863aa120b4f645869f584013e4c4dba46a",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"ext-curl": "*",
|
|
||||||
"ext-json": "*",
|
|
||||||
"ext-zip": "*",
|
|
||||||
"php": "^7.3 || ^8.0",
|
|
||||||
"symfony/polyfill-mbstring": "^1.12",
|
|
||||||
"symfony/process": "^5.0 || ^6.0 || ^7.0 || ^8.0"
|
|
||||||
},
|
|
||||||
"replace": {
|
|
||||||
"facebook/webdriver": "*"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"ergebnis/composer-normalize": "^2.20.0",
|
|
||||||
"ondram/ci-detector": "^4.0",
|
|
||||||
"php-coveralls/php-coveralls": "^2.4",
|
|
||||||
"php-mock/php-mock-phpunit": "^2.0",
|
|
||||||
"php-parallel-lint/php-parallel-lint": "^1.2",
|
|
||||||
"phpunit/phpunit": "^9.3",
|
|
||||||
"squizlabs/php_codesniffer": "^3.5",
|
|
||||||
"symfony/var-dumper": "^5.0 || ^6.0 || ^7.0 || ^8.0"
|
|
||||||
},
|
|
||||||
"suggest": {
|
|
||||||
"ext-simplexml": "For Firefox profile creation"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"autoload": {
|
|
||||||
"files": [
|
|
||||||
"lib/Exception/TimeoutException.php"
|
|
||||||
],
|
|
||||||
"psr-4": {
|
|
||||||
"Facebook\\WebDriver\\": "lib/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"description": "A PHP client for Selenium WebDriver. Previously facebook/webdriver.",
|
|
||||||
"homepage": "https://github.com/php-webdriver/php-webdriver",
|
|
||||||
"keywords": [
|
|
||||||
"Chromedriver",
|
|
||||||
"geckodriver",
|
|
||||||
"php",
|
|
||||||
"selenium",
|
|
||||||
"webdriver"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/php-webdriver/php-webdriver/issues",
|
|
||||||
"source": "https://github.com/php-webdriver/php-webdriver/tree/1.16.0"
|
|
||||||
},
|
|
||||||
"time": "2025-12-28T23:57:40+00:00"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "phpstan/phpstan",
|
"name": "phpstan/phpstan",
|
||||||
"version": "2.2.2",
|
"version": "2.2.2",
|
||||||
|
|||||||
@ -13,11 +13,10 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('predefined_mutations', function (Blueprint $table) {
|
Schema::create('predefined_mutations', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('dynamic_id')->constrained()->cascadeOnDelete();
|
$table->foreignId('ledger_id')->constrained()->cascadeOnDelete();
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->text('description')->nullable();
|
$table->text('description')->nullable();
|
||||||
$table->integer('amount');
|
$table->integer('amount');
|
||||||
$table->string('type')->default('reward');
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,30 +0,0 @@
|
|||||||
<?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('messages', function (Blueprint $table) {
|
|
||||||
DB::table('messages')->where('subject_type', 'App\\Models\\User')->update(['subject_type' => 'user']);
|
|
||||||
DB::table('messages')->where('subject_type', 'App\\Models\\Mutation')->update(['subject_type' => 'mutation']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('messages', function (Blueprint $table) {
|
|
||||||
DB::table('messages')->where('subject_type', 'user')->update(['subject_type' => 'App\\Models\\User']);
|
|
||||||
DB::table('messages')->where('subject_type', 'mutation')->update(['subject_type' => 'App\\Models\\Mutation']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
<?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('users', function (Blueprint $table) {
|
|
||||||
$table->dropUnique('users_uuid_unique');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('users', function (Blueprint $table) {
|
|
||||||
$table->unique('uuid');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
<?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('predefined_mutations', function (Blueprint $table) {
|
|
||||||
// Drop old foreign key constraint first
|
|
||||||
$table->dropForeign(['dynamic_id']);
|
|
||||||
|
|
||||||
// Drop old columns
|
|
||||||
$table->dropColumn(['dynamic_id', 'type']);
|
|
||||||
|
|
||||||
// Add new ledger relationship (nullable to support pre-existing entries gracefully)
|
|
||||||
$table->foreignId('ledger_id')
|
|
||||||
->after('id')
|
|
||||||
->nullable()
|
|
||||||
->constrained()
|
|
||||||
->cascadeOnDelete();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('predefined_mutations', function (Blueprint $table) {
|
|
||||||
$table->dropConstrainedForeignId('ledger_id');
|
|
||||||
$table->foreignId('dynamic_id')->after('id')->constrained()->cascadeOnDelete();
|
|
||||||
$table->string('type')->default('reward');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,11 +1,9 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { usePage } from '@inertiajs/vue3';
|
import { useForm, usePage, router } from '@inertiajs/vue3';
|
||||||
import { useEcho, echoIsConfigured, configureEcho } from '@laravel/echo-vue';
|
import { useEcho, echoIsConfigured, configureEcho } from '@laravel/echo-vue';
|
||||||
|
import { Paperclip, Info } from '@lucide/vue';
|
||||||
import { ref, computed, watch } from 'vue';
|
import { ref, computed, watch } from 'vue';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
import ChatInput from './chat/ChatInput.vue';
|
|
||||||
import ChatSystemMessage from './chat/ChatSystemMessage.vue';
|
|
||||||
import ChatUserMessage from './chat/ChatUserMessage.vue';
|
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
@ -133,10 +131,30 @@ if (!echoIsConfigured()) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fileInput = ref<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
|
const form = useForm({
|
||||||
|
content: '',
|
||||||
|
media: [] as File[],
|
||||||
|
});
|
||||||
|
|
||||||
useEcho(`chats.${props.chat.id}`, 'MessageSent', (e: any) => {
|
useEcho(`chats.${props.chat.id}`, 'MessageSent', (e: any) => {
|
||||||
messages.value.push(e.message);
|
messages.value.push(e.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function formatTimestamp(isoString: string): { full: string; time: string } {
|
||||||
|
const date = new Date(isoString);
|
||||||
|
|
||||||
|
return {
|
||||||
|
full: date.toLocaleString(),
|
||||||
|
time: date.toLocaleTimeString([], {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const participantsById = computed(() => {
|
const participantsById = computed(() => {
|
||||||
const list = props.participants || [];
|
const list = props.participants || [];
|
||||||
|
|
||||||
@ -157,6 +175,83 @@ const participantsById = computed(() => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function parseMessageContent(message: {
|
||||||
|
content: string;
|
||||||
|
subject_id?: number | null;
|
||||||
|
subject_type?: string | null;
|
||||||
|
subject?: any;
|
||||||
|
}) {
|
||||||
|
let content = message.content;
|
||||||
|
|
||||||
|
// 1. Replace <user:id> placeholders with links to their dynamic profile
|
||||||
|
const userRegex = /<user:(\d+)>/g;
|
||||||
|
content = content.replace(userRegex, (match, userId) => {
|
||||||
|
const user = participantsById.value[Number(userId)];
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
const url = route('dynamics.users.show', [props.dynamicId, Number(userId)]);
|
||||||
|
|
||||||
|
return `<a href="${url}" class="c-chat__user-link font-semibold text-blue-500 hover:underline">${
|
||||||
|
user.pivot?.display_name ?? user.name
|
||||||
|
}</a>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `User #${userId}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Link subjects if found in the text
|
||||||
|
if (message.subject_id && message.subject_type) {
|
||||||
|
if (
|
||||||
|
message.subject_type === 'App\\Models\\Mutation' ||
|
||||||
|
message.subject_type === 'App\\Models\\Ledger'
|
||||||
|
) {
|
||||||
|
const ledgerId =
|
||||||
|
message.subject_type === 'App\\Models\\Mutation'
|
||||||
|
? message.subject?.ledger_id
|
||||||
|
: message.subject?.id;
|
||||||
|
|
||||||
|
const ledgerName =
|
||||||
|
message.subject_type === 'App\\Models\\Mutation'
|
||||||
|
? message.subject?.ledger?.name
|
||||||
|
: message.subject?.name;
|
||||||
|
|
||||||
|
if (ledgerId && ledgerName) {
|
||||||
|
const ledgerUrl = route('dynamics.ledgers.show', [
|
||||||
|
props.dynamicId,
|
||||||
|
ledgerId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const escapedName = ledgerName.replace(
|
||||||
|
/[-\/\\^$*+?.()|[\]{}]/g,
|
||||||
|
'\\$&',
|
||||||
|
);
|
||||||
|
|
||||||
|
const nameRegex = new RegExp(`"${escapedName}"`, 'g');
|
||||||
|
content = content.replace(
|
||||||
|
nameRegex,
|
||||||
|
`"<a href="${ledgerUrl}" class="c-chat__subject-link font-semibold text-blue-500 hover:underline">${ledgerName}</a>"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleFileChange(event: Event) {
|
||||||
|
const files = (event.target as HTMLInputElement).files;
|
||||||
|
|
||||||
|
if (files) {
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
form.media.push(files[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeFile(index: number) {
|
||||||
|
form.media.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
const currentUser = computed(() => usePage().props.auth?.user);
|
const currentUser = computed(() => usePage().props.auth?.user);
|
||||||
|
|
||||||
function isOwnMessage(messageUserId: number | null): boolean {
|
function isOwnMessage(messageUserId: number | null): boolean {
|
||||||
@ -167,6 +262,19 @@ function isOwnMessage(messageUserId: number | null): boolean {
|
|||||||
return currentUser.value && currentUser.value.id === messageUserId;
|
return currentUser.value && currentUser.value.id === messageUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function submit() {
|
||||||
|
form.post(route('chats.messages.store', props.chat.id), {
|
||||||
|
preserveScroll: true,
|
||||||
|
onSuccess: () => {
|
||||||
|
form.reset();
|
||||||
|
|
||||||
|
if (fileInput.value) {
|
||||||
|
fileInput.value.value = '';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Lightbox Modal state
|
// Lightbox Modal state
|
||||||
const activeLightboxUrl = ref<string | null>(null);
|
const activeLightboxUrl = ref<string | null>(null);
|
||||||
const activeLightboxType = ref<'image' | 'video' | null>(null);
|
const activeLightboxType = ref<'image' | 'video' | null>(null);
|
||||||
@ -206,29 +314,138 @@ function closeLightbox() {
|
|||||||
]"
|
]"
|
||||||
>
|
>
|
||||||
<!-- Standard User Chat Message -->
|
<!-- Standard User Chat Message -->
|
||||||
<ChatUserMessage
|
<template v-if="message.user">
|
||||||
v-if="message.user"
|
<div class="c-chat__message-header">
|
||||||
:message="message"
|
<span class="c-chat__message-author">{{
|
||||||
:participants-by-id="participantsById"
|
message.user.name
|
||||||
:dynamic-id="dynamicId"
|
}}</span>
|
||||||
@open-lightbox="openLightbox"
|
<span
|
||||||
/>
|
class="c-chat__message-time"
|
||||||
|
:title="formatTimestamp(message.created_at).full"
|
||||||
|
>
|
||||||
|
{{ formatTimestamp(message.created_at).time }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p class="c-chat__message-text" v-html="parseMessageContent(message)"></p>
|
||||||
|
|
||||||
|
<!-- Attached Media Display -->
|
||||||
|
<div
|
||||||
|
v-if="message.media && message.media.length > 0"
|
||||||
|
class="c-chat__message-media"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="item in message.media"
|
||||||
|
:key="item.id"
|
||||||
|
class="c-chat__media-item"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-if="item.mime_type.startsWith('image/')"
|
||||||
|
:src="item.url"
|
||||||
|
:alt="item.file_name"
|
||||||
|
class="c-chat__image cursor-pointer transition-opacity hover:opacity-90"
|
||||||
|
@click="openLightbox(item.url, item.mime_type)"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-else-if="item.mime_type.startsWith('video/')"
|
||||||
|
class="relative cursor-pointer transition-opacity hover:opacity-90"
|
||||||
|
@click="openLightbox(item.url, item.mime_type)"
|
||||||
|
>
|
||||||
|
<video
|
||||||
|
:src="item.url"
|
||||||
|
class="c-chat__video"
|
||||||
|
></video>
|
||||||
|
<div class="c-chat__play-overlay">▶</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<!-- Subtle Activity Log System Message -->
|
<!-- Subtle Activity Log System Message -->
|
||||||
<ChatSystemMessage
|
<template v-else>
|
||||||
v-else
|
<div class="c-chat__system-inner">
|
||||||
:message="message"
|
<Info class="c-chat__system-icon" />
|
||||||
:participants-by-id="participantsById"
|
<span
|
||||||
:dynamic-id="dynamicId"
|
class="c-chat__system-text"
|
||||||
/>
|
v-html="parseMessageContent(message)"
|
||||||
|
></span>
|
||||||
|
<span
|
||||||
|
class="c-chat__system-time"
|
||||||
|
:title="formatTimestamp(message.created_at).full"
|
||||||
|
>
|
||||||
|
{{ formatTimestamp(message.created_at).time }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="messages.length === 0" class="c-chat__empty">
|
<div v-if="messages.length === 0" class="c-chat__empty">
|
||||||
No messages yet.
|
No messages yet.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<form @submit.prevent="submit" class="c-chat__form">
|
||||||
|
<div class="c-chat__form-group">
|
||||||
|
<label for="content" class="c-chat__label">Message</label>
|
||||||
|
<textarea
|
||||||
|
v-model="form.content"
|
||||||
|
id="content"
|
||||||
|
rows="3"
|
||||||
|
class="c-chat__textarea"
|
||||||
|
placeholder="Type a message... (Press Enter to send, Shift+Enter for newline)"
|
||||||
|
@keydown.enter.exact.prevent="submit"
|
||||||
|
></textarea>
|
||||||
|
<div v-if="form.errors.content" class="c-chat__error">
|
||||||
|
{{ form.errors.content }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Cohesive Chat input Form -->
|
<!-- Attachment Button & Hidden Input -->
|
||||||
<ChatInput :chat-id="chat.id" />
|
<div class="c-chat__attachment-container">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
@click="fileInput?.click()"
|
||||||
|
class="c-chat__attach-btn"
|
||||||
|
>
|
||||||
|
<Paperclip class="c-chat__attach-icon" />
|
||||||
|
Attach Photos/Videos
|
||||||
|
</button>
|
||||||
|
<input
|
||||||
|
ref="fileInput"
|
||||||
|
type="file"
|
||||||
|
multiple
|
||||||
|
accept="image/*,video/*"
|
||||||
|
class="hidden"
|
||||||
|
@change="handleFileChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Previews List -->
|
||||||
|
<div v-if="form.media.length > 0" class="c-chat__preview-list">
|
||||||
|
<div
|
||||||
|
v-for="(file, index) in form.media"
|
||||||
|
:key="index"
|
||||||
|
class="c-chat__preview-item"
|
||||||
|
>
|
||||||
|
<span class="c-chat__preview-name">{{
|
||||||
|
file.name
|
||||||
|
}}</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
@click="removeFile(index)"
|
||||||
|
class="c-chat__preview-remove"
|
||||||
|
>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="c-chat__submit-box">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
:disabled="form.processing"
|
||||||
|
class="c-chat__button"
|
||||||
|
>
|
||||||
|
Send
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
<!-- Gorgeous Dark Lightbox Modal -->
|
<!-- Gorgeous Dark Lightbox Modal -->
|
||||||
<div v-if="activeLightboxUrl" class="c-lightbox" @click="closeLightbox">
|
<div v-if="activeLightboxUrl" class="c-lightbox" @click="closeLightbox">
|
||||||
@ -250,183 +467,3 @@ function closeLightbox() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
@reference "../../css/app.css";
|
|
||||||
|
|
||||||
.c-chat {
|
|
||||||
@apply flex flex-col h-[500px];
|
|
||||||
background-color: var(--card);
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: var(--radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__title {
|
|
||||||
@apply p-4 font-bold border-b text-sm;
|
|
||||||
border-color: var(--border);
|
|
||||||
color: var(--foreground);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__list {
|
|
||||||
@apply flex-1 overflow-y-auto p-4 space-y-4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__load-more {
|
|
||||||
@apply flex justify-center py-2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__load-more-btn {
|
|
||||||
@apply text-xs font-semibold text-blue-500 hover:underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__message {
|
|
||||||
@apply max-w-[75%] p-3 rounded-lg flex flex-col gap-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__message--own {
|
|
||||||
@apply self-end;
|
|
||||||
background-color: var(--primary);
|
|
||||||
color: var(--primary-foreground);
|
|
||||||
border-bottom-right-radius: 0;
|
|
||||||
|
|
||||||
.c-chat__message-author {
|
|
||||||
@apply hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__message-time {
|
|
||||||
@apply text-blue-100;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__message-text {
|
|
||||||
color: var(--primary-foreground);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__message--other {
|
|
||||||
@apply self-start;
|
|
||||||
background-color: var(--muted);
|
|
||||||
color: var(--muted-foreground);
|
|
||||||
border-bottom-left-radius: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__message--system {
|
|
||||||
@apply self-center max-w-full w-full bg-transparent border-0 p-0 text-center gap-0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__message-header {
|
|
||||||
@apply flex items-baseline gap-2 mb-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__message-author {
|
|
||||||
@apply font-semibold text-xs;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__message-time {
|
|
||||||
@apply text-[10px];
|
|
||||||
color: var(--muted-foreground);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__message-text {
|
|
||||||
@apply text-sm break-words whitespace-pre-wrap leading-relaxed;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__message-media {
|
|
||||||
@apply mt-2 flex flex-wrap gap-2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__media-item {
|
|
||||||
@apply max-w-[120px] overflow-hidden rounded border border-black dark:border-gray-600 bg-black;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__image {
|
|
||||||
@apply h-auto max-h-[80px] w-full object-cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__video {
|
|
||||||
@apply h-auto max-h-[80px] w-full;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__play-overlay {
|
|
||||||
@apply absolute inset-0 flex items-center justify-center bg-black/40 text-lg font-bold text-white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__system-inner {
|
|
||||||
@apply inline-flex items-center gap-2 bg-neutral-100 dark:bg-neutral-900/30 px-3 py-1 rounded-full text-xs text-neutral-500 dark:text-neutral-400;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__system-icon {
|
|
||||||
@apply size-3.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__system-text {
|
|
||||||
@apply font-medium leading-relaxed;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__system-time {
|
|
||||||
@apply text-[10px] opacity-75 ml-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__empty {
|
|
||||||
@apply text-center text-xs py-8;
|
|
||||||
color: var(--muted-foreground);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__form {
|
|
||||||
@apply p-4 border-t flex flex-col gap-2 bg-neutral-50 dark:bg-neutral-900/10;
|
|
||||||
border-color: var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__form-group {
|
|
||||||
@apply relative flex flex-col gap-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__label {
|
|
||||||
@apply sr-only;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__textarea {
|
|
||||||
@apply w-full rounded border p-2 text-sm resize-none focus:outline-none focus:ring-1 focus:ring-blue-500 dark:bg-neutral-900 dark:border-neutral-800;
|
|
||||||
color: var(--foreground);
|
|
||||||
border-color: var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__error {
|
|
||||||
@apply text-xs text-red-500 mt-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__attachment-container {
|
|
||||||
@apply flex items-center mt-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__attach-btn {
|
|
||||||
@apply inline-flex items-center gap-1.5 text-xs text-neutral-500 hover:text-neutral-900 dark:hover:text-neutral-100 transition-colors;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__attach-icon {
|
|
||||||
@apply size-3.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__preview-list {
|
|
||||||
@apply mt-2 flex flex-wrap gap-2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__preview-item {
|
|
||||||
@apply inline-flex items-center gap-2 bg-neutral-100 dark:bg-neutral-900/50 px-2 py-1 rounded text-xs;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__preview-name {
|
|
||||||
@apply max-w-[150px] truncate text-neutral-600 dark:text-neutral-400;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__preview-remove {
|
|
||||||
@apply text-neutral-400 hover:text-red-500 transition-colors;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__submit-box {
|
|
||||||
@apply flex justify-end mt-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-chat__button {
|
|
||||||
@apply inline-flex items-center justify-center rounded-md border border-transparent bg-gray-800 px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase transition duration-150 ease-in-out hover:bg-gray-700 focus:bg-gray-700 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none active:bg-gray-900 dark:bg-gray-200 dark:text-gray-800 dark:hover:bg-white dark:focus:bg-white dark:focus:ring-offset-gray-800 dark:active:bg-gray-300;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@ -196,7 +196,7 @@ function getAmountClass(amount: number): string {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Chat v-if="mutation.chat" :chat="mutation.chat" :dynamic-id="dynamicId" :participants="participants" />
|
<Chat :chat="mutation.chat" :dynamic-id="dynamicId" :participants="participants" />
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div v-if="mutations.length === 0" class="c-mutation-list__empty">
|
<div v-if="mutations.length === 0" class="c-mutation-list__empty">
|
||||||
|
|||||||
@ -1,112 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { useForm } from '@inertiajs/vue3';
|
|
||||||
import { Paperclip } from '@lucide/vue';
|
|
||||||
import { ref } from 'vue';
|
|
||||||
import { route } from 'ziggy-js';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
chatId: number;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const fileInput = ref<HTMLInputElement | null>(null);
|
|
||||||
|
|
||||||
const form = useForm({
|
|
||||||
content: '',
|
|
||||||
media: [] as File[],
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleFileChange(event: Event) {
|
|
||||||
const files = (event.target as HTMLInputElement).files;
|
|
||||||
|
|
||||||
if (files) {
|
|
||||||
for (let i = 0; i < files.length; i++) {
|
|
||||||
form.media.push(files[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeFile(index: number) {
|
|
||||||
form.media.splice(index, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function submit() {
|
|
||||||
form.post(route('chats.messages.store', props.chatId), {
|
|
||||||
preserveScroll: true,
|
|
||||||
onSuccess: () => {
|
|
||||||
form.reset();
|
|
||||||
|
|
||||||
if (fileInput.value) {
|
|
||||||
fileInput.value.value = '';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<form @submit.prevent="submit" class="c-chat__form">
|
|
||||||
<div class="c-chat__form-group">
|
|
||||||
<label for="content" class="c-chat__label">Message</label>
|
|
||||||
<textarea
|
|
||||||
v-model="form.content"
|
|
||||||
id="content"
|
|
||||||
rows="3"
|
|
||||||
class="c-chat__textarea"
|
|
||||||
placeholder="Type a message... (Press Enter to send, Shift+Enter for newline)"
|
|
||||||
@keydown.enter.exact.prevent="submit"
|
|
||||||
></textarea>
|
|
||||||
<div v-if="form.errors.content" class="c-chat__error">
|
|
||||||
{{ form.errors.content }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Attachment Button & Hidden Input -->
|
|
||||||
<div class="c-chat__attachment-container">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
@click="fileInput?.click()"
|
|
||||||
class="c-chat__attach-btn"
|
|
||||||
>
|
|
||||||
<Paperclip class="c-chat__attach-icon" />
|
|
||||||
Attach Photos/Videos
|
|
||||||
</button>
|
|
||||||
<input
|
|
||||||
ref="fileInput"
|
|
||||||
type="file"
|
|
||||||
multiple
|
|
||||||
accept="image/*,video/*"
|
|
||||||
class="hidden"
|
|
||||||
@change="handleFileChange"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Previews List -->
|
|
||||||
<div v-if="form.media.length > 0" class="c-chat__preview-list">
|
|
||||||
<div
|
|
||||||
v-for="(file, index) in form.media"
|
|
||||||
:key="index"
|
|
||||||
class="c-chat__preview-item"
|
|
||||||
>
|
|
||||||
<span class="c-chat__preview-name">{{
|
|
||||||
file.name
|
|
||||||
}}</span>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
@click="removeFile(index)"
|
|
||||||
class="c-chat__preview-remove"
|
|
||||||
>
|
|
||||||
✕
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="c-chat__submit-box">
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
:disabled="form.processing"
|
|
||||||
class="c-chat__button"
|
|
||||||
>
|
|
||||||
Send
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</template>
|
|
||||||
@ -1,108 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { computed } from 'vue';
|
|
||||||
import { route } from 'ziggy-js';
|
|
||||||
import { Info } from '@lucide/vue';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
message: {
|
|
||||||
id: number;
|
|
||||||
content: string;
|
|
||||||
created_at: string;
|
|
||||||
subject_id?: number | null;
|
|
||||||
subject_type?: string | null;
|
|
||||||
subject?: any;
|
|
||||||
};
|
|
||||||
participantsById: Record<
|
|
||||||
number,
|
|
||||||
{
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
pivot?: { display_name: string | null } | null;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
dynamicId: string;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
function formatTimestamp(isoString: string): { full: string; time: string } {
|
|
||||||
const date = new Date(isoString);
|
|
||||||
return {
|
|
||||||
full: date.toLocaleString(),
|
|
||||||
time: date.toLocaleTimeString([], {
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
hour12: false,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsedContent = computed(() => {
|
|
||||||
let content = props.message.content;
|
|
||||||
|
|
||||||
// 1. Replace <user:id> placeholders with links to their dynamic profile
|
|
||||||
const userRegex = /<user:(\d+)>/g;
|
|
||||||
content = content.replace(userRegex, (match, userId) => {
|
|
||||||
const user = props.participantsById[Number(userId)];
|
|
||||||
if (user) {
|
|
||||||
const url = route('dynamics.users.show', [props.dynamicId, Number(userId)]);
|
|
||||||
return `<a href="${url}" class="c-chat__user-link font-semibold text-blue-500 hover:underline">${
|
|
||||||
user.pivot?.display_name ?? user.name
|
|
||||||
}</a>`;
|
|
||||||
}
|
|
||||||
return `User #${userId}`;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 2. Link subjects if found in the text
|
|
||||||
if (props.message.subject_id && props.message.subject_type) {
|
|
||||||
if (
|
|
||||||
props.message.subject_type === 'mutation' ||
|
|
||||||
props.message.subject_type === 'ledger'
|
|
||||||
) {
|
|
||||||
const ledgerId =
|
|
||||||
props.message.subject_type === 'mutation'
|
|
||||||
? props.message.subject?.ledger_id
|
|
||||||
: props.message.subject?.id;
|
|
||||||
|
|
||||||
const ledgerName =
|
|
||||||
props.message.subject_type === 'mutation'
|
|
||||||
? props.message.subject?.ledger?.name
|
|
||||||
: props.message.subject?.name;
|
|
||||||
|
|
||||||
if (ledgerId && ledgerName) {
|
|
||||||
const ledgerUrl = route('dynamics.ledgers.show', [
|
|
||||||
props.dynamicId,
|
|
||||||
ledgerId,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const escapedName = ledgerName.replace(
|
|
||||||
/[-\/\\^$*+?.()|[\]{}]/g,
|
|
||||||
'\\$&',
|
|
||||||
);
|
|
||||||
|
|
||||||
const nameRegex = new RegExp(`"${escapedName}"`, 'g');
|
|
||||||
content = content.replace(
|
|
||||||
nameRegex,
|
|
||||||
`"<a href="${ledgerUrl}" class="c-chat__subject-link font-semibold text-blue-500 hover:underline">${ledgerName}</a>"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return content;
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="c-chat__system-inner">
|
|
||||||
<Info class="c-chat__system-icon" />
|
|
||||||
<span
|
|
||||||
class="c-chat__system-text"
|
|
||||||
v-html="parsedContent"
|
|
||||||
></span>
|
|
||||||
<span
|
|
||||||
class="c-chat__system-time"
|
|
||||||
:title="formatTimestamp(message.created_at).full"
|
|
||||||
>
|
|
||||||
{{ formatTimestamp(message.created_at).time }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@ -1,150 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { computed } from 'vue';
|
|
||||||
import { route } from 'ziggy-js';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
message: {
|
|
||||||
id: number;
|
|
||||||
user: { id: number; name: string } | null;
|
|
||||||
content: string;
|
|
||||||
created_at: string;
|
|
||||||
subject_id?: number | null;
|
|
||||||
subject_type?: string | null;
|
|
||||||
subject?: any;
|
|
||||||
media?: Array<{
|
|
||||||
id: number;
|
|
||||||
url: string;
|
|
||||||
file_name: string;
|
|
||||||
mime_type: string;
|
|
||||||
}>;
|
|
||||||
};
|
|
||||||
participantsById: Record<
|
|
||||||
number,
|
|
||||||
{
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
pivot?: { display_name: string | null } | null;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
dynamicId: string;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
(e: 'open-lightbox', url: string, mimeType: string): void;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
function formatTimestamp(isoString: string): { full: string; time: string } {
|
|
||||||
const date = new Date(isoString);
|
|
||||||
return {
|
|
||||||
full: date.toLocaleString(),
|
|
||||||
time: date.toLocaleTimeString([], {
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
hour12: false,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsedContent = computed(() => {
|
|
||||||
let content = props.message.content;
|
|
||||||
|
|
||||||
// 1. Replace <user:id> placeholders with links to their dynamic profile
|
|
||||||
const userRegex = /<user:(\d+)>/g;
|
|
||||||
content = content.replace(userRegex, (match, userId) => {
|
|
||||||
const user = props.participantsById[Number(userId)];
|
|
||||||
if (user) {
|
|
||||||
const url = route('dynamics.users.show', [props.dynamicId, Number(userId)]);
|
|
||||||
return `<a href="${url}" class="c-chat__user-link font-semibold text-blue-500 hover:underline">${
|
|
||||||
user.pivot?.display_name ?? user.name
|
|
||||||
}</a>`;
|
|
||||||
}
|
|
||||||
return `User #${userId}`;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 2. Link subjects if found in the text
|
|
||||||
if (props.message.subject_id && props.message.subject_type) {
|
|
||||||
if (
|
|
||||||
props.message.subject_type === 'mutation' ||
|
|
||||||
props.message.subject_type === 'ledger'
|
|
||||||
) {
|
|
||||||
const ledgerId =
|
|
||||||
props.message.subject_type === 'mutation'
|
|
||||||
? props.message.subject?.ledger_id
|
|
||||||
: props.message.subject?.id;
|
|
||||||
|
|
||||||
const ledgerName =
|
|
||||||
props.message.subject_type === 'mutation'
|
|
||||||
? props.message.subject?.ledger?.name
|
|
||||||
: props.message.subject?.name;
|
|
||||||
|
|
||||||
if (ledgerId && ledgerName) {
|
|
||||||
const ledgerUrl = route('dynamics.ledgers.show', [
|
|
||||||
props.dynamicId,
|
|
||||||
ledgerId,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const escapedName = ledgerName.replace(
|
|
||||||
/[-\/\\^$*+?.()|[\]{}]/g,
|
|
||||||
'\\$&',
|
|
||||||
);
|
|
||||||
|
|
||||||
const nameRegex = new RegExp(`"${escapedName}"`, 'g');
|
|
||||||
content = content.replace(
|
|
||||||
nameRegex,
|
|
||||||
`"<a href="${ledgerUrl}" class="c-chat__subject-link font-semibold text-blue-500 hover:underline">${ledgerName}</a>"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return content;
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<div class="c-chat__message-header">
|
|
||||||
<span class="c-chat__message-author">{{
|
|
||||||
message.user?.name
|
|
||||||
}}</span>
|
|
||||||
<span
|
|
||||||
class="c-chat__message-time"
|
|
||||||
:title="formatTimestamp(message.created_at).full"
|
|
||||||
>
|
|
||||||
{{ formatTimestamp(message.created_at).time }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p class="c-chat__message-text" v-html="parsedContent"></p>
|
|
||||||
|
|
||||||
<!-- Attached Media Display -->
|
|
||||||
<div
|
|
||||||
v-if="message.media && message.media.length > 0"
|
|
||||||
class="c-chat__message-media"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
v-for="item in message.media"
|
|
||||||
:key="item.id"
|
|
||||||
class="c-chat__media-item"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
v-if="item.mime_type.startsWith('image/')"
|
|
||||||
:src="item.url"
|
|
||||||
:alt="item.file_name"
|
|
||||||
class="c-chat__image cursor-pointer transition-opacity hover:opacity-90"
|
|
||||||
@click="emit('open-lightbox', item.url, item.mime_type)"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
v-else-if="item.mime_type.startsWith('video/')"
|
|
||||||
class="relative cursor-pointer transition-opacity hover:opacity-90"
|
|
||||||
@click="emit('open-lightbox', item.url, item.mime_type)"
|
|
||||||
>
|
|
||||||
<video
|
|
||||||
:src="item.url"
|
|
||||||
class="c-chat__video"
|
|
||||||
></video>
|
|
||||||
<div class="c-chat__play-overlay">▶</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@ -14,7 +14,7 @@ defineOptions({
|
|||||||
});
|
});
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
unreadEntities: Array<{
|
unreadDynamics: Array<{
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
url: string;
|
url: string;
|
||||||
@ -50,10 +50,10 @@ function formatTime(isoString: string): string {
|
|||||||
<div class="c-dashboard__container">
|
<div class="c-dashboard__container">
|
||||||
<h2 class="c-dashboard__title">Recent Activity</h2>
|
<h2 class="c-dashboard__title">Recent Activity</h2>
|
||||||
|
|
||||||
<div v-if="unreadEntities.length > 0" class="c-dashboard__grid">
|
<div v-if="unreadDynamics.length > 0" class="c-dashboard__grid">
|
||||||
<div
|
<div
|
||||||
v-for="entity in unreadEntities"
|
v-for="dynamic in unreadDynamics"
|
||||||
:key="entity.id"
|
:key="dynamic.id"
|
||||||
class="c-dashboard__card"
|
class="c-dashboard__card"
|
||||||
>
|
>
|
||||||
<div class="c-dashboard__card-header">
|
<div class="c-dashboard__card-header">
|
||||||
|
|||||||
38
tests/Browser/AuthenticationTest.php
Normal file
38
tests/Browser/AuthenticationTest.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Browser;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Laravel\Dusk\Browser;
|
||||||
|
|
||||||
|
test('user can register, log in, and log out', function () {
|
||||||
|
$this->browse(function (Browser $browser) {
|
||||||
|
// 1. Test Registration
|
||||||
|
$browser->visit('/register')
|
||||||
|
->waitForText('Create an account')
|
||||||
|
->type('name', 'New Browser User')
|
||||||
|
->type('email', 'newbrowseruser@example.com')
|
||||||
|
->type('password', 'password')
|
||||||
|
->type('password_confirmation', 'password')
|
||||||
|
->press('Create account')
|
||||||
|
->waitForLocation('/dashboard')
|
||||||
|
->assertPathIs('/dashboard')
|
||||||
|
->assertSee('New Browser User');
|
||||||
|
|
||||||
|
// 2. Test Logout
|
||||||
|
// Open the user menu (trigger button shows initials or user name)
|
||||||
|
$browser->click('button[aria-haspopup="menu"]')
|
||||||
|
->waitForText('Log out')
|
||||||
|
->clickLink('Log out')
|
||||||
|
->waitForLocation('/login') // Fortify logs out and redirects to login or home
|
||||||
|
->assertPathIs('/login');
|
||||||
|
|
||||||
|
// 3. Test Login
|
||||||
|
$browser->type('email', 'newbrowseruser@example.com')
|
||||||
|
->type('password', 'password')
|
||||||
|
->press('Log in')
|
||||||
|
->waitForLocation('/dashboard')
|
||||||
|
->assertPathIs('/dashboard')
|
||||||
|
->assertSee('New Browser User');
|
||||||
|
});
|
||||||
|
});
|
||||||
82
tests/Browser/AuthorizationTest.php
Normal file
82
tests/Browser/AuthorizationTest.php
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Browser;
|
||||||
|
|
||||||
|
use App\Models\Dynamic;
|
||||||
|
use App\Models\Ledger;
|
||||||
|
use App\Models\Mutation;
|
||||||
|
use App\Models\User;
|
||||||
|
use Laravel\Dusk\Browser;
|
||||||
|
|
||||||
|
test('access control and actions are enforced for owners and participants', function () {
|
||||||
|
// Create database state
|
||||||
|
$owner = User::factory()->create([
|
||||||
|
'name' => 'Owner Alice',
|
||||||
|
'email' => 'alice-owner@example.com',
|
||||||
|
'password' => bcrypt('password'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$participant = User::factory()->create([
|
||||||
|
'name' => 'Participant Bob',
|
||||||
|
'email' => 'bob-sub@example.com',
|
||||||
|
'password' => bcrypt('password'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$outsider = User::factory()->create([
|
||||||
|
'name' => 'Outsider Charlie',
|
||||||
|
'email' => 'charlie-outsider@example.com',
|
||||||
|
'password' => bcrypt('password'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$dynamic = Dynamic::create([
|
||||||
|
'name' => 'Private Club',
|
||||||
|
'rules' => 'Strict access control.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
||||||
|
|
||||||
|
$ledger = Ledger::create([
|
||||||
|
'dynamic_id' => $dynamic->id,
|
||||||
|
'name' => 'Rules Compliance',
|
||||||
|
'rules' => 'Score rules.',
|
||||||
|
'score' => 100,
|
||||||
|
'alignment' => 'neutral',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->browse(function (Browser $sessionOwner, Browser $sessionParticipant, Browser $sessionOutsider) use ($dynamic, $ledger, $owner, $participant, $outsider) {
|
||||||
|
|
||||||
|
// 1. Test Outsider trying to access dynamic they DO NOT belong to (should be forbidden / 403)
|
||||||
|
$sessionOutsider->loginAs($outsider)
|
||||||
|
->visit(route('dynamics.show', $dynamic))
|
||||||
|
->assertSee('403') // Laravel / Inertia forbidden page
|
||||||
|
->assertDontSee('Private Club');
|
||||||
|
|
||||||
|
// 2. Test Participant accessing dynamic they DO belong to (should be allowed)
|
||||||
|
$sessionParticipant->loginAs($participant)
|
||||||
|
->visit(route('dynamics.show', $dynamic))
|
||||||
|
->waitForText('Private Club')
|
||||||
|
->assertSee('Private Club')
|
||||||
|
->assertSee('Participant Bob');
|
||||||
|
|
||||||
|
// 3. Test Participant adding a mutation suggestion
|
||||||
|
$sessionParticipant->visit(route('dynamics.ledgers.show', [$dynamic, $ledger]))
|
||||||
|
->waitForText('Add Mutation')
|
||||||
|
->type('amount', '20')
|
||||||
|
->type('description', 'Cleaned the main room')
|
||||||
|
->press('Add Mutation')
|
||||||
|
->waitForText('PENDING')
|
||||||
|
->assertSee('PENDING') // Mutation should show up as pending
|
||||||
|
->assertDontSee('Approve'); // Standard participant should NOT see approve button!
|
||||||
|
|
||||||
|
// 4. Test Owner logging in, seeing the pending suggestion, and approving it!
|
||||||
|
$sessionOwner->loginAs($owner)
|
||||||
|
->visit(route('dynamics.ledgers.show', [$dynamic, $ledger]))
|
||||||
|
->waitForText('Cleaned the main room')
|
||||||
|
->assertSee('PENDING')
|
||||||
|
->assertSee('Approve') // Owner should see the Approve button!
|
||||||
|
->press('Approve')
|
||||||
|
->waitForText('Score: 120') // Score updated from 100 to 120 after approval!
|
||||||
|
->assertDontSee('PENDING'); // No longer pending!
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,138 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Browser;
|
|
||||||
|
|
||||||
use App\Models\Dynamic;
|
|
||||||
use App\Models\Ledger;
|
|
||||||
use App\Models\User;
|
|
||||||
use Laravel\Dusk\Browser;
|
|
||||||
use Tests\DuskTestCase;
|
|
||||||
|
|
||||||
class BasicViewsTest extends DuskTestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Test that guests can visit the welcome page.
|
|
||||||
*/
|
|
||||||
public function test_guests_can_visit_the_welcome_page(): void
|
|
||||||
{
|
|
||||||
$this->browse(function (Browser $browser) {
|
|
||||||
$browser->visit('/')
|
|
||||||
->waitForText("Let's get started")
|
|
||||||
->assertSee("Let's get started");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that authenticated users can visit the dynamics index and see their dynamics.
|
|
||||||
*/
|
|
||||||
public function test_authenticated_users_can_visit_the_dynamics_index(): void
|
|
||||||
{
|
|
||||||
$user = User::factory()->create();
|
|
||||||
$dynamic = Dynamic::factory()->create([
|
|
||||||
'name' => 'Dusk Automated Dynamic Index Test',
|
|
||||||
]);
|
|
||||||
$dynamic->participants()->attach($user->id, ['role' => 'owner']);
|
|
||||||
|
|
||||||
$this->browse(function (Browser $browser) use ($user, $dynamic) {
|
|
||||||
$browser->loginAs($user)
|
|
||||||
->visit('/dynamics')
|
|
||||||
->waitForText('Your Dynamics')
|
|
||||||
->assertSee('Your Dynamics')
|
|
||||||
->assertSee($dynamic->name);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
$dynamic->participants()->detach();
|
|
||||||
$dynamic->delete();
|
|
||||||
$user->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that authenticated users can visit a dynamic show page.
|
|
||||||
*/
|
|
||||||
public function test_authenticated_users_can_visit_a_dynamic_show_page(): void
|
|
||||||
{
|
|
||||||
$user = User::factory()->create();
|
|
||||||
$dynamic = Dynamic::factory()->create([
|
|
||||||
'name' => 'Dusk Dynamic Show Test',
|
|
||||||
'rules' => 'Rule 1: Always obey the automation.',
|
|
||||||
]);
|
|
||||||
$dynamic->participants()->attach($user->id, ['role' => 'owner']);
|
|
||||||
|
|
||||||
$this->browse(function (Browser $browser) use ($user, $dynamic) {
|
|
||||||
$browser->loginAs($user)
|
|
||||||
->visit('/dynamics/' . $dynamic->uuid)
|
|
||||||
->waitForText($dynamic->name)
|
|
||||||
->assertSee($dynamic->name)
|
|
||||||
->assertSee($dynamic->rules);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
$dynamic->participants()->detach();
|
|
||||||
$dynamic->delete();
|
|
||||||
$user->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that authenticated users can visit a ledger show page.
|
|
||||||
*/
|
|
||||||
public function test_authenticated_users_can_visit_a_ledger_show_page(): void
|
|
||||||
{
|
|
||||||
$user = User::factory()->create();
|
|
||||||
$dynamic = Dynamic::factory()->create([
|
|
||||||
'name' => 'Dusk Dynamic Ledger Show Test',
|
|
||||||
]);
|
|
||||||
$dynamic->participants()->attach($user->id, ['role' => 'owner']);
|
|
||||||
|
|
||||||
$ledger = Ledger::factory()->create([
|
|
||||||
'dynamic_id' => $dynamic->id,
|
|
||||||
'name' => 'Dusk Ledger Test',
|
|
||||||
'score' => 42,
|
|
||||||
'rules' => 'Scores are tracked for Dusk automated verification.',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->browse(function (Browser $browser) use ($user, $dynamic, $ledger) {
|
|
||||||
$browser->loginAs($user)
|
|
||||||
->visit('/dynamics/' . $dynamic->uuid . '/ledgers/' . $ledger->uuid)
|
|
||||||
->waitForText($ledger->name)
|
|
||||||
->assertSee($ledger->name)
|
|
||||||
->assertSee('Score: 42')
|
|
||||||
->assertSee($ledger->rules);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
$ledger->delete();
|
|
||||||
$dynamic->participants()->detach();
|
|
||||||
$dynamic->delete();
|
|
||||||
$user->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that authenticated users can visit a participant profile page.
|
|
||||||
*/
|
|
||||||
public function test_authenticated_users_can_visit_a_participant_profile_page(): void
|
|
||||||
{
|
|
||||||
$user = User::factory()->create();
|
|
||||||
$dynamic = Dynamic::factory()->create([
|
|
||||||
'name' => 'Dusk Participant Profile Test',
|
|
||||||
]);
|
|
||||||
$dynamic->participants()->attach($user->id, ['role' => 'owner', 'display_name' => 'The Master']);
|
|
||||||
|
|
||||||
$otherUser = User::factory()->create();
|
|
||||||
$dynamic->participants()->attach($otherUser->id, ['role' => 'participant', 'display_name' => 'Bitch Bob']);
|
|
||||||
|
|
||||||
$this->browse(function (Browser $browser) use ($user, $dynamic, $otherUser) {
|
|
||||||
$browser->loginAs($user)
|
|
||||||
->visit('/dynamics/' . $dynamic->uuid . '/users/' . $otherUser->uuid)
|
|
||||||
->waitForText('Bitch Bob')
|
|
||||||
->assertSee('Bitch Bob')
|
|
||||||
->assertSee('participant');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
$dynamic->participants()->detach();
|
|
||||||
$dynamic->delete();
|
|
||||||
$user->delete();
|
|
||||||
$otherUser->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Laravel\Dusk\Browser;
|
|
||||||
use Tests\DuskTestCase;
|
|
||||||
use App\Models\User;
|
|
||||||
|
|
||||||
class DashboardTest extends DuskTestCase
|
|
||||||
{
|
|
||||||
public function test_authenticated_users_can_visit_the_dashboard(): void
|
|
||||||
{
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
$this->browse(function (Browser $browser) use ($user) {
|
|
||||||
$browser->loginAs($user)
|
|
||||||
->visit('/dashboard')
|
|
||||||
->assertSee('Recent Activity');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Laravel\Dusk\Browser;
|
|
||||||
use Tests\DuskTestCase;
|
|
||||||
use App\Models\User;
|
|
||||||
|
|
||||||
class LoginTest extends DuskTestCase
|
|
||||||
{
|
|
||||||
public function test_a_user_can_log_in(): void
|
|
||||||
{
|
|
||||||
User::where('email', 'dusk@example.com')->delete();
|
|
||||||
|
|
||||||
$user = User::factory()->create([
|
|
||||||
'email' => 'dusk@example.com',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->browse(function (Browser $browser) use ($user) {
|
|
||||||
$browser->visit('/login')
|
|
||||||
->waitFor('#email')
|
|
||||||
->type('email', $user->email)
|
|
||||||
->type('password', 'wrong-password')
|
|
||||||
->press('[data-test="login-button"]')
|
|
||||||
->assertPathIs('/login')
|
|
||||||
->screenshot('login-error');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Browser\Pages;
|
|
||||||
|
|
||||||
use Laravel\Dusk\Browser;
|
|
||||||
|
|
||||||
class HomePage extends Page
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the URL for the page.
|
|
||||||
*/
|
|
||||||
public function url(): string
|
|
||||||
{
|
|
||||||
return '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assert that the browser is on the page.
|
|
||||||
*/
|
|
||||||
public function assert(Browser $browser): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the element shortcuts for the page.
|
|
||||||
*
|
|
||||||
* @return array<string, string>
|
|
||||||
*/
|
|
||||||
public function elements(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'@element' => '#selector',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Browser\Pages;
|
|
||||||
|
|
||||||
use Laravel\Dusk\Page as BasePage;
|
|
||||||
|
|
||||||
abstract class Page extends BasePage
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get the global element shortcuts for the site.
|
|
||||||
*
|
|
||||||
* @return array<string, string>
|
|
||||||
*/
|
|
||||||
public static function siteElements(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'@element' => '#selector',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,82 +5,61 @@ namespace Tests\Browser;
|
|||||||
use App\Models\Dynamic;
|
use App\Models\Dynamic;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Laravel\Dusk\Browser;
|
use Laravel\Dusk\Browser;
|
||||||
use Tests\DuskTestCase;
|
|
||||||
|
|
||||||
class RealtimeChatTest extends DuskTestCase
|
test('multiple sessions can communicate in real time through websockets', function () {
|
||||||
{
|
// 1. Create realistic database state
|
||||||
/**
|
$owner = User::factory()->create([
|
||||||
* Test that multiple browser sessions can communicate in real time through websockets.
|
'name' => 'TU Test User',
|
||||||
*/
|
'email' => 'test-owner@example.com',
|
||||||
public function test_multiple_sessions_can_communicate_in_real_time(): void
|
'password' => bcrypt('password'),
|
||||||
{
|
]);
|
||||||
// 1. Create realistic database state
|
|
||||||
$owner = User::factory()->create([
|
|
||||||
'name' => 'Owner Alice',
|
|
||||||
'email' => 'alice-owner-' . uniqid() . '@example.com',
|
|
||||||
'password' => bcrypt('password'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$participant = User::factory()->create([
|
$participant = User::factory()->create([
|
||||||
'name' => 'Submissive Bob',
|
'name' => 'Submissive Bob',
|
||||||
'email' => 'bob-participant-' . uniqid() . '@example.com',
|
'email' => 'test-sub@example.com',
|
||||||
'password' => bcrypt('password'),
|
'password' => bcrypt('password'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$dynamic = Dynamic::create([
|
$dynamic = Dynamic::create([
|
||||||
'name' => 'The Velvet Realtime Test Sanctuary',
|
'name' => 'The Test Sanctuary',
|
||||||
'rules' => 'Rules for realtime testing.',
|
'rules' => 'Rules for realtime testing.',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
||||||
|
|
||||||
// 2. Spawn two separate browser sessions/browsers in parallel
|
// 2. Spawn two separate browser sessions/browsers in parallel
|
||||||
$this->browse(function (Browser $sessionA, Browser $sessionB) use ($dynamic, $owner, $participant) {
|
$this->browse(function (Browser $sessionA, Browser $sessionB) use ($dynamic, $owner, $participant) {
|
||||||
try {
|
|
||||||
// --- SESSION A: Owner ---
|
|
||||||
$sessionA->loginAs($owner)
|
|
||||||
->visit('/dynamics/' . $dynamic->uuid)
|
|
||||||
->waitForText('The Velvet Realtime Test Sanctuary')
|
|
||||||
->assertSee('Owner Alice');
|
|
||||||
|
|
||||||
// --- SESSION B: Participant ---
|
// --- SESSION A: Owner ---
|
||||||
$sessionB->loginAs($participant)
|
$sessionA->loginAs($owner)
|
||||||
->visit('/dynamics/' . $dynamic->uuid)
|
->visit(route('dynamics.show', $dynamic))
|
||||||
->waitForText('The Velvet Realtime Test Sanctuary')
|
->waitForText('The Test Sanctuary')
|
||||||
->assertSee('Submissive Bob');
|
->assertSee('TU Test User'); // Verify loaded in as Owner
|
||||||
|
|
||||||
// --- REAL-TIME COMMUNICATING ---
|
// --- SESSION B: Participant ---
|
||||||
// Owner types and sends a message in chat
|
$sessionB->loginAs($participant)
|
||||||
$sessionA->type('#content', 'Hello Submissive Bob, did you complete your daily chores?')
|
->visit(route('dynamics.show', $dynamic))
|
||||||
->click('.c-chat__button')
|
->waitForText('The Test Sanctuary')
|
||||||
->waitForText('Hello Submissive Bob, did you complete your daily chores?');
|
->assertSee('Submissive Bob'); // Verify loaded in as Submissive/Participant
|
||||||
|
|
||||||
// Since websockets broadcast in real-time, Session B receives it without reloading
|
// --- REAL-TIME COMMUNICATING ---
|
||||||
$sessionB->waitForText('Hello Submissive Bob, did you complete your daily chores?', 10)
|
// Owner types and sends a message in chat
|
||||||
->assertSee('Hello Submissive Bob, did you complete your daily chores?');
|
$sessionA->type('#content', 'Hello Submissive Bob, did you complete your daily chores?')
|
||||||
|
->click('.c-chat__button')
|
||||||
|
->waitForText('Hello Submissive Bob');
|
||||||
|
|
||||||
// Participant replies in real-time
|
// Since websockets broadcast in real-time, Session B receives it without reloading
|
||||||
$sessionB->type('#content', 'Yes Master, everything is complete and logged!')
|
$sessionB->waitForText('Hello Submissive Bob', 5)
|
||||||
->click('.c-chat__button')
|
->assertSee('Hello Submissive Bob, did you complete your daily chores?');
|
||||||
->waitForText('Yes Master, everything is complete and logged!');
|
|
||||||
|
|
||||||
// Session A receives the reply in real-time without reloading
|
// Participant replies in real-time
|
||||||
$sessionA->waitForText('Yes Master, everything is complete and logged!', 10)
|
$sessionB->type('#content', 'Yes Master, everything is complete and logged in the ledger!')
|
||||||
->assertSee('Yes Master, everything is complete and logged!');
|
->click('.c-chat__button')
|
||||||
} catch (\Exception $e) {
|
->waitForText('Yes Master, everything is complete');
|
||||||
echo "\n=== SESSION A CONSOLE LOGS ===\n";
|
|
||||||
print_r($sessionA->driver->manage()->getLog('browser'));
|
|
||||||
echo "\n=== SESSION B CONSOLE LOGS ===\n";
|
|
||||||
print_r($sessionB->driver->manage()->getLog('browser'));
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clean up
|
// Session A receives the reply in real-time without reloading
|
||||||
$dynamic->participants()->detach();
|
$sessionA->waitForText('Yes Master, everything is complete', 5)
|
||||||
$dynamic->delete();
|
->assertSee('Yes Master, everything is complete and logged in the ledger!');
|
||||||
$owner->delete();
|
});
|
||||||
$participant->delete();
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -7,8 +7,6 @@ use Facebook\WebDriver\Remote\DesiredCapabilities;
|
|||||||
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
||||||
use Laravel\Dusk\TestCase as BaseTestCase;
|
use Laravel\Dusk\TestCase as BaseTestCase;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
abstract class DuskTestCase extends BaseTestCase
|
abstract class DuskTestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -28,13 +26,13 @@ abstract class DuskTestCase extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
protected function driver(): RemoteWebDriver
|
protected function driver(): RemoteWebDriver
|
||||||
{
|
{
|
||||||
$options = (new ChromeOptions)->addArguments((new Collection([
|
$options = (new ChromeOptions)->addArguments(collect([
|
||||||
$this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080',
|
$this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080',
|
||||||
'--disable-gpu',
|
'--disable-gpu',
|
||||||
'--headless=new',
|
'--headless=new',
|
||||||
'--no-sandbox',
|
'--no-sandbox',
|
||||||
'--disable-dev-shm-usage',
|
'--disable-dev-shm-usage',
|
||||||
]))->unless(static::runningInSail(), function (Collection $arguments) {
|
])->unless(static::runningInSail(), function (collect $arguments) {
|
||||||
return $arguments->push('--disable-smooth-scrolling');
|
return $arguments->push('--disable-smooth-scrolling');
|
||||||
})->all());
|
})->all());
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ test('authenticated users can visit the dashboard', function () {
|
|||||||
|
|
||||||
$response = $this->get(route('dashboard'));
|
$response = $this->get(route('dashboard'));
|
||||||
$response->assertOk();
|
$response->assertOk();
|
||||||
$response->assertInertia(fn ($page) => $page->component('Dashboard')->has('unreadEntities'));
|
$response->assertInertia(fn ($page) => $page->component('Dashboard')->has('unreadDynamics'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('visiting dynamic updates the read cursor', function () {
|
test('visiting dynamic updates the read cursor', function () {
|
||||||
@ -100,12 +100,12 @@ test('dashboard groups and filters unread entities correctly based on cursor', f
|
|||||||
// Verify unread grouping structure
|
// Verify unread grouping structure
|
||||||
$response->assertInertia(fn ($page) => $page
|
$response->assertInertia(fn ($page) => $page
|
||||||
->component('Dashboard')
|
->component('Dashboard')
|
||||||
->where('unreadEntities.0.name', 'Testing Dynamic')
|
->where('unreadDynamics.0.name', 'Testing Dynamic')
|
||||||
->where('unreadEntities.0.unread_count', 1)
|
->where('unreadDynamics.0.unread_count', 1)
|
||||||
->has('unreadEntities.0.context_activities', 1) // Should have old message as context
|
->has('unreadDynamics.0.context_activities', 1) // Should have old message as context
|
||||||
->where('unreadEntities.0.context_activities.0.content', 'Old message context')
|
->where('unreadDynamics.0.context_activities.0.content', 'Old message context')
|
||||||
->has('unreadEntities.0.new_activities', 1) // Should have unread message
|
->has('unreadDynamics.0.new_activities', 1) // Should have unread message
|
||||||
->where('unreadEntities.0.new_activities.0.content', 'New unread message alert')
|
->where('unreadDynamics.0.new_activities.0.content', 'New unread message alert')
|
||||||
);
|
);
|
||||||
|
|
||||||
// Now visit the Dynamic, which clears the unread count
|
// Now visit the Dynamic, which clears the unread count
|
||||||
@ -116,7 +116,7 @@ test('dashboard groups and filters unread entities correctly based on cursor', f
|
|||||||
$response2->assertOk();
|
$response2->assertOk();
|
||||||
$response2->assertInertia(fn ($page) => $page
|
$response2->assertInertia(fn ($page) => $page
|
||||||
->component('Dashboard')
|
->component('Dashboard')
|
||||||
->has('unreadEntities', 0)
|
->has('unreadDynamics', 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
Carbon::setTestNow(); // Reset test time
|
Carbon::setTestNow(); // Reset test time
|
||||||
|
|||||||
@ -21,7 +21,7 @@ test('authenticated participant can view another participant detail page in dyna
|
|||||||
$response->assertInertia(fn ($page) => $page
|
$response->assertInertia(fn ($page) => $page
|
||||||
->component('Dynamics/Participants/Show')
|
->component('Dynamics/Participants/Show')
|
||||||
->has('dynamic')
|
->has('dynamic')
|
||||||
->where('participant.id', $participant->uuid)
|
->where('participant.id', $participant->id)
|
||||||
->where('participant.name', $participant->name)
|
->where('participant.name', $participant->name)
|
||||||
->where('participant.display_name', null)
|
->where('participant.display_name', null)
|
||||||
->where('participant.role', 'participant')
|
->where('participant.role', 'participant')
|
||||||
|
|||||||
@ -25,8 +25,8 @@ test('owner can view predefined mutations for ledger', function () {
|
|||||||
$response->assertOk();
|
$response->assertOk();
|
||||||
$response->assertInertia(fn ($page) => $page
|
$response->assertInertia(fn ($page) => $page
|
||||||
->component('Ledgers/PredefinedMutations/Index')
|
->component('Ledgers/PredefinedMutations/Index')
|
||||||
->where('dynamic.id', $dynamic->uuid)
|
->where('dynamic.id', $dynamic->id)
|
||||||
->where('ledger.id', $ledger->uuid)
|
->where('ledger.id', $ledger->id)
|
||||||
->has('predefined_mutations', 1)
|
->has('predefined_mutations', 1)
|
||||||
->where('predefined_mutations.0.name', 'Weekly Room Cleaning')
|
->where('predefined_mutations.0.name', 'Weekly Room Cleaning')
|
||||||
);
|
);
|
||||||
@ -112,7 +112,7 @@ test('owner can view edit form for predefined mutation', function () {
|
|||||||
$response->assertOk();
|
$response->assertOk();
|
||||||
$response->assertInertia(fn ($page) => $page
|
$response->assertInertia(fn ($page) => $page
|
||||||
->component('Ledgers/PredefinedMutations/Edit')
|
->component('Ledgers/PredefinedMutations/Edit')
|
||||||
->where('predefined_mutation.id', $predefined->uuid)
|
->where('predefined_mutation.id', $predefined->id)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
pest()->extend(Tests\DuskTestCase::class)
|
|
||||||
// ->use(Illuminate\Foundation\Testing\DatabaseMigrations::class)
|
|
||||||
->in('Browser');
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user