diff --git a/src/lib/push-background-task.ts b/src/lib/push-background-task.ts index 9ba215aa..8cb9539c 100644 --- a/src/lib/push-background-task.ts +++ b/src/lib/push-background-task.ts @@ -11,6 +11,25 @@ import { const PUSH_ACCOUNT_ID_KEY = 'push:accountId:v1'; const LAST_NOTIFIED_EMAIL_ID_KEY = 'push:lastNotifiedEmailId:v1'; +// Mirrors STORAGE_KEY in `stores/settings-store.ts`. The headless task can't +// import the Zustand store (would pull in React) so we read AsyncStorage +// directly. Keep this in sync if the store key ever changes. +const SETTINGS_STORAGE_KEY = 'webmail:settings:v1'; + +interface PushPersistedSettings { + emailNotificationsEnabled?: boolean; +} + +async function emailNotificationsAllowed(): Promise { + try { + const raw = await AsyncStorage.getItem(SETTINGS_STORAGE_KEY); + if (!raw) return true; // first launch: default to on + const parsed = JSON.parse(raw) as PushPersistedSettings; + return parsed.emailNotificationsEnabled !== false; + } catch { + return true; + } +} interface ShowNotificationOptions { notificationId: string; @@ -33,6 +52,8 @@ interface BulwarkFcmNative { // resolve so the native service can release its wake lock. export async function pushBackgroundTask(_data: unknown): Promise { try { + if (!(await emailNotificationsAllowed())) return; + const accountId = await AsyncStorage.getItem(PUSH_ACCOUNT_ID_KEY); if (!accountId) return; diff --git a/src/stores/email-store.ts b/src/stores/email-store.ts index ddf5ab4a..eec671d9 100644 --- a/src/stores/email-store.ts +++ b/src/stores/email-store.ts @@ -151,7 +151,8 @@ export const useEmailStore = create()( }); try { const filter = buildJmapFilter(mailboxId, '', {}); - const { ids, total } = await queryEmails(mailboxId, { limit: 50, filter }); + const limit = useSettingsStore.getState().emailsPerPage; + const { ids, total } = await queryEmails(mailboxId, { limit, filter }); const emails = ids.length > 0 ? await fetchEmails(ids) : []; set({ emails, totalEmails: total, loading: false }); } catch (err) { @@ -167,9 +168,10 @@ export const useEmailStore = create()( set({ loading: true }); try { const filter = buildJmapFilter(currentMailboxId, searchQuery, filters); + const limit = useSettingsStore.getState().emailsPerPage; const { ids } = await queryEmails(currentMailboxId, { position: emails.length, - limit: 50, + limit, filter, }); const newEmails = ids.length > 0 ? await fetchEmails(ids) : []; @@ -187,7 +189,8 @@ export const useEmailStore = create()( set({ loading: true, error: null }); try { const filter = buildJmapFilter(currentMailboxId, searchQuery, filters); - const { ids, total } = await queryEmails(currentMailboxId, { limit: 50, filter }); + const limit = useSettingsStore.getState().emailsPerPage; + const { ids, total } = await queryEmails(currentMailboxId, { limit, filter }); const emails = ids.length > 0 ? await fetchEmails(ids) : []; set({ emails, totalEmails: total, loading: false }); } catch (err) {