Step 5: Real-time broadcasting (NewEmailReceived event, channel routes, Livewire listener)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user