diff --git a/client/src/mobile/components/MPushPrompt.test.tsx b/client/src/mobile/components/MPushPrompt.test.tsx
index cb0117064..5b50bb9c0 100644
--- a/client/src/mobile/components/MPushPrompt.test.tsx
+++ b/client/src/mobile/components/MPushPrompt.test.tsx
@@ -46,10 +46,12 @@ describe('MPushPrompt', () => {
it('FE-MOB-PUSHPROMPT-001: a moment after signing in the app asks, and turning it on goes the settings card way', async () => {
await renderAndWait();
expect(screen.getByText('Turn on notifications?')).toBeInTheDocument();
- expect(window.localStorage.getItem(PUSH_PROMPT_KEY)).not.toBeNull();
+ // Asked once answered, not once shown.
+ expect(window.localStorage.getItem(PUSH_PROMPT_KEY)).toBeNull();
fireEvent.click(screen.getByRole('button', { name: 'Turn on' }));
expect(env.toggle).toHaveBeenCalledTimes(1);
+ expect(window.localStorage.getItem(PUSH_PROMPT_KEY)).not.toBeNull();
expect(screen.queryByText('Turn on notifications?')).not.toBeInTheDocument();
});
@@ -77,6 +79,18 @@ describe('MPushPrompt', () => {
expect(window.localStorage.getItem(PUSH_PROMPT_KEY)).toBeNull();
});
+ it('FE-MOB-PUSHPROMPT-005: a prompt left unanswered asks again on the next launch', async () => {
+ const first = render();
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(PUSH_PROMPT_DELAY_MS);
+ });
+ expect(screen.getByText('Turn on notifications?')).toBeInTheDocument();
+ first.unmount();
+
+ await renderAndWait();
+ expect(screen.getByText('Turn on notifications?')).toBeInTheDocument();
+ });
+
it('FE-MOB-PUSHPROMPT-004: signed out, it waits', async () => {
useAuthStore.setState({ isAuthenticated: false } as never);
await renderAndWait();
diff --git a/client/src/mobile/components/MPushPrompt.tsx b/client/src/mobile/components/MPushPrompt.tsx
index 85ecb4546..fc469a316 100644
--- a/client/src/mobile/components/MPushPrompt.tsx
+++ b/client/src/mobile/components/MPushPrompt.tsx
@@ -2,6 +2,7 @@ import { BellRing } from 'lucide-react';
import React, { useEffect, useState } from 'react';
import { useWebPush } from '../../hooks/useWebPush';
import { useTranslation } from '../../i18n';
+import { useNativeCapabilities } from '../../native/capabilities';
import { nativePushActive, nativePushEndpoint } from '../../native/push';
import { pushChannelOffered } from '../../push/webPush';
import { useAuthStore } from '../../store/authStore';
@@ -36,9 +37,14 @@ function rememberAsked(): void {
* server offers push, and only while this device is not signed up yet. Turning
* it on goes the way the settings' push card goes (useWebPush), which brings up
* the system's question.
+ *
+ * It counts as asked once the user answers it, not when it opens: a sheet that
+ * went under another one, or an app closed while it was up, asks again. And it
+ * waits for the app's capabilities, which can arrive after the sign-in.
*/
export default function MPushPrompt(): React.ReactElement | null {
const signedIn = useAuthStore((s) => s.isAuthenticated);
+ const { caps } = useNativeCapabilities();
const [open, setOpen] = useState(false);
useEffect(() => {
@@ -46,8 +52,7 @@ export default function MPushPrompt(): React.ReactElement | null {
let cancelled = false;
const timer = window.setTimeout(() => {
void pushChannelOffered().then((offered) => {
- if (cancelled || !offered || nativePushEndpoint()) return;
- rememberAsked();
+ if (cancelled || !offered || nativePushEndpoint() || alreadyAsked()) return;
setOpen(true);
});
}, PUSH_PROMPT_DELAY_MS);
@@ -55,9 +60,13 @@ export default function MPushPrompt(): React.ReactElement | null {
cancelled = true;
window.clearTimeout(timer);
};
- }, [signedIn]);
+ }, [signedIn, caps]);
- return open ? setOpen(false)} /> : null;
+ const answered = () => {
+ rememberAsked();
+ setOpen(false);
+ };
+ return open ? : null;
}
function PushPromptSheet({ onClose }: { onClose: () => void }): React.ReactElement {