false]; $dismissed = (bool) session('mailbox_link_banner_dismissed', false); if ($account?->public_id) { $mailboxOptions = []; try { $mailboxOptions = $this->mailboxes->forUser((string) $account->public_id); } catch (\Throwable $e) { report($e); } try { $status = $this->identity->mailboxLinkStatus((string) $account->public_id); } catch (\Throwable $e) { report($e); $status = $this->localMailboxLinkStatus($account, $mailboxOptions); } if (! ($status['show_reminder'] ?? false) && $this->localNeedsMailboxLink($account, $mailboxOptions, $status)) { $status['show_reminder'] = true; $status['stage'] = $status['stage'] ?? 'needs_link'; $status['account_email'] = $status['account_email'] ?? $account->email; } } $view->with('mailboxLinkReminder', [ ...$status, 'visible' => ($status['show_reminder'] ?? false) && ! $dismissed, ]); } /** @param array> $mailboxOptions */ private function localNeedsMailboxLink(User $account, array $mailboxOptions, array $status): bool { if ($status['linked_mailbox'] ?? null) { return false; } $email = strtolower(trim($account->email ?? '')); if ($email === '') { return false; } foreach ($mailboxOptions as $mailbox) { if (strtolower((string) ($mailbox['address'] ?? '')) === $email) { return false; } } return count($mailboxOptions) > 0; } /** @param array> $mailboxOptions */ /** @return array */ private function localMailboxLinkStatus(User $account, array $mailboxOptions): array { $needsLink = $this->localNeedsMailboxLink($account, $mailboxOptions, []); return [ 'show_reminder' => $needsLink, 'stage' => count($mailboxOptions) > 0 ? 'needs_link' : 'needs_mailbox', 'linked_mailbox' => null, 'account_email' => $account->email, ]; } }