Step 5: Real-time broadcasting (NewEmailReceived event, channel routes, Livewire listener)

This commit is contained in:
idevakk
2026-03-05 14:14:04 +05:30
parent dc5029e8cb
commit ac9e7227e6
3 changed files with 104 additions and 3 deletions

View File

@@ -40,6 +40,37 @@ class Mailbox extends Component
public $availableDomains = ['imail.com', 'devmail.ai', 'temp-inbox.net'];
/**
* Get Reverb/Echo event listeners for the current mailbox domain.
*
* @return array<string, string>
*/
public function getListeners(): array
{
$currentMailbox = collect($this->activeMailboxes)->firstWhere('id', $this->currentMailboxId);
$domain = $currentMailbox ? explode('@', $currentMailbox['address'])[1] ?? '' : '';
if (empty($domain)) {
return [];
}
return [
"echo:mailbox.{$domain},.new.email" => 'onNewEmail',
];
}
/**
* Handle a new email broadcast event from Reverb.
*
* @param array<string, mixed> $eventData The email data from the broadcast.
*/
public function onNewEmail(array $eventData): void
{
// TODO: When real data integration is complete, prepend the new email to the list.
// For now, trigger a component refresh to pick up new data.
$this->dispatch('$refresh');
}
public function getEmailsProperty()
{
// Mock emails based on mailbox ID