mirror of
https://github.com/bulwarkmail/native.git
synced 2026-10-31 08:06:36 +00:00
Signing in sent two full `Mailbox/get`s before the inbox loaded, and the first only went out once the main screen had mounted and painted. There is no deliberate delay behind the gap: the mail screen's mount effect started the folder load, and the push setup read the same folders again with a `Mailbox/get` of its own (plus the shared accounts') just to find the Junk folders for its filter. The latter also happened on every start with push notifications on. - Sign-in (password and OAuth/pairing) starts the folder load as soon as the session is up, like a restored session already did. - The mail screen's mount now joins a load on its way (`ensureMailboxes`) instead of queueing another behind it. - The push filter takes the folders from the mail store (joining its load) and only fetches them itself when the store has none for the account.
30 lines
995 B
TypeScript
30 lines
995 B
TypeScript
// The folder list the mail store holds (or is loading) for the signed-in
|
|
// account, for code below the stores that needs it too: the push filter's
|
|
// Junk folders. It used to send a full `Mailbox/get` of its own right next to
|
|
// the store's on every sign-in and start. The mail store registers the
|
|
// provider, so nothing here imports it.
|
|
|
|
import type { Mailbox } from '../api/types';
|
|
|
|
type Provider = (accountId: string) => Promise<Mailbox[] | null>;
|
|
|
|
let provider: Provider | null = null;
|
|
|
|
export function provideLoadedMailboxes(next: Provider | null): void {
|
|
provider = next;
|
|
}
|
|
|
|
/**
|
|
* The own and shared folders of `accountId` (the account registry id) once
|
|
* the store has them, joining a sync that is on its way. Null when the store
|
|
* serves another account or could not load them.
|
|
*/
|
|
export async function loadedMailboxes(accountId: string): Promise<Mailbox[] | null> {
|
|
if (!provider) return null;
|
|
try {
|
|
return await provider(accountId);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|