Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions routes/channels.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use Illuminate\Support\Facades\Broadcast;
use App\Models\ResearchSpace;
use App\Models\ResearchSpaceCollaborator;

/*
|--------------------------------------------------------------------------
Expand All @@ -14,3 +16,23 @@
*/

Broadcast::channel('App.Models.User.{id}', fn($user, $id): bool => (int) $user->id === (int) $id);

// Channel for ResearchSpace real-time updates.
// A user may listen if they are the owner or a collaborator on the space.
Broadcast::channel('research-space.{id}', function ($user, $id) {
try {
$space = ResearchSpace::find($id);
if (! $space) {
return false;
}
if ($space->owner_id === $user->id) {
return true;
}

return ResearchSpaceCollaborator::where('research_space_id', $id)
->where('user_id', $user->id)
->exists();
} catch (\Throwable $e) {
return false;
}
});
Loading