fix: let a link wait for a mailbox that is still reconnecting

A notification tapped with the app closed reopens it on a link that names
its mailbox (`?slot=`). The browser reconnects its logins one at a time,
so that mailbox is often not connected yet when the link is read: with ten
logins, one on the Gmail bridge came back at 3.3 s and the link was judged
at 1.8 s. It was declared unavailable - "sign in to that account to open
this link" - and the app stayed on whichever mailbox was active.

Wait for the login instead, and give up only when it is not one of this
browser's logins, its restore fails, or 20 s go by.
This commit is contained in:
lucamzanon
2026-09-30 19:01:14 +02:00
parent 7f5728fea2
commit 1c5dbbcd0b
3 changed files with 109 additions and 5 deletions
+5 -5
View File
@@ -26,7 +26,7 @@ import { ProtocolAccountPicker } from "@/components/protocol/protocol-account-pi
import { ThreadConversationView } from "@/components/email/thread-conversation-view";
import { MobileHeader } from "@/components/layout/mobile-header";
import { ThreadGroup, Email, Mailbox, isUnifiedMailboxId, UNIFIED_ROLE_BY_ID, CROSS_VIEW_BY_ID, isCrossViewId } from "@/lib/jmap/types";
import { useAccountStore } from "@/stores/account-store";
import { useAccountStore, waitForConnectedAccount } from "@/stores/account-store";
import { usePolicyStore } from "@/stores/policy-store";
import type { UnifiedAccountClient } from "@/lib/unified-mailbox";
import { connectedAccountsGrew } from "@/lib/unified-mailbox";
@@ -1375,10 +1375,10 @@ export function MailApp({ linkSegments: routeSegments }: MailAppProps = {}) {
: undefined);
const switchesAccount = !!linkAccountId && linkAccountId !== useAuthStore.getState().activeAccountId;
if (switchesAccount) {
const target = useAccountStore.getState().accounts.find(
(a) => a.id === linkAccountId && a.isConnected,
);
if (!target) {
// The login may still be reconnecting - a tapped notification reopens
// the app and the logins come back one at a time - so wait for it
// rather than calling a late mailbox unavailable.
if (!(await waitForConnectedAccount(linkAccountId))) {
toast.error(t('deep_link.account_unavailable'));
return;
}