One solution would be to create a separate presence channel for the table view and exclude the current user from that channel. Here's an example of how you could implement this:
- Create a new presence channel for the table view:
Broadcast::channel('table-view', function ($user) {
return true;
});
- In your table view, join the
table-viewchannel:
Echo.join('table-view')
.here(users => {
// handle initial presence data
})
.joining(user => {
// handle new user joining
})
.leaving(user => {
// handle user leaving
});
- When a user visits a task page, join the task's presence channel as usual:
Echo.join(`task.${taskId}`)
.here(users => {
// handle initial presence data
})
.joining(user => {
// handle new user joining
})
.leaving(user => {
// handle user leaving
});
- In your task page view, use the
Echoinstance to get the current user's ID:
let userId = Echo.socketId();
- When rendering the table view, pass the current user's ID to the view:
return view('table', [
'currentUserId' => $currentUserId,
// other data
]);
- In your table view, use the
currentUserIdto exclude the current user from thetable-viewchannel:
Echo.join('table-view')
.here(users => {
// handle initial presence data
})
.joining(user => {
// handle new user joining
})
.leaving(user => {
// handle user leaving
})
.whisper('exclude', currentUserId);
- In your JavaScript code that handles the warning message, check if the current user's ID is in the presence data for the task channel. If it is, don't show the warning message for that task.
Echo.join(`task.${taskId}`)
.here(users => {
// handle initial presence data
let isCurrentUserWorking = users.some(user => user.id === currentUserId);
if (isCurrentUserWorking) {
// don't show warning message
} else {
// show warning message
}
})
.joining(user => {
// handle new user joining
if (user.id === currentUserId) {
// don't show warning message
} else {
// show warning message
}
})
.leaving(user => {
// handle user leaving
if (user.id === currentUserId) {
// don't show warning message
} else {
// show warning message
}
});
This solution allows you to exclude the current user from the table-view channel while still using presence channels to display the warning message for individual tasks.