Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(ios): restore push notification reply navigation (#7845)
Peter Chinmanbd3c47aa9f93
diff --git a/apps/web/src/lib/tauri/PushNotification.test.tsx b/apps/web/src/lib/tauri/PushNotification.test.tsxdeleted file mode 100644index 5dbc1a7ab2..0000000000--- a/apps/web/src/lib/tauri/PushNotification.test.tsx+++ /dev/null@@ -1,352 +0,0 @@-import type { PushRegistrationLifecycle } from '@core/auth/push-registration-lifecycle';-import type { PlatformNotificationInterface } from '@notifications';-import { cleanup, render } from '@solidjs/testing-library';-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import type { PushEvent } from './push-api';--const mock = vi.hoisted(() => ({- loggedIn: true,- lifecycle: undefined as PushRegistrationLifecycle | undefined,- watcher: undefined as ((event: PushEvent) => void) | undefined,- check: vi.fn(),- request: vi.fn(),- register: vi.fn(),- configure: vi.fn(),- unwatch: vi.fn(),- watch: vi.fn(),- registerDevice: vi.fn(),- unregisterDevice: vi.fn(),- recipient: vi.fn(),- navigate: vi.fn(),- acknowledge: vi.fn(),- localShow: vi.fn(),- notifications: undefined as PlatformNotificationInterface | undefined,-}));--vi.mock('@core/util/cookies', () => ({ hasLoginCookie: () => mock.loggedIn }));-vi.mock('@core/auth/push-registration-lifecycle', () => ({- registerPushRegistrationLifecycle: (lifecycle: PushRegistrationLifecycle) => {- mock.lifecycle = lifecycle;- return () => {};- },- syncPushRegistrations: async () => {- await mock.lifecycle?.syncRegistration();- },-}));-vi.mock('@queries/notification/device-registration', () => ({- fetchPushRecipient: mock.recipient,- registerPushDevice: mock.registerDevice,- unregisterPushDevice: mock.unregisterDevice,-}));-vi.mock('@notifications', () => ({- PlatformNotificationProvider: (props: {- children: unknown;- overrideDefault: (- disabled: () => Promise<void>- ) => PlatformNotificationInterface;- }) => {- mock.notifications = props.overrideDefault(async () => {});- return props.children;- },- triggerNotificationNavigation: mock.navigate,-}));-vi.mock('@tauri-apps/plugin-notification', () => ({- removeAllActive: vi.fn(async () => {}),-}));-vi.mock('./notification', () => ({- createTauriNotificationInterface: () => ({- showNotification: mock.localShow,- requestPermission: async () => 'granted',- getCurrentPermission: async () => 'granted',- unregisterNotifications: async () => {},- }),-}));-vi.mock('./TauriProvider', () => ({- useExpectTauri: () => ({ os: 'android' }),-}));-vi.mock('./push-api', () => ({- createPushApi: () => ({- checkPermissions: mock.check,- requestPermissions: mock.request,- register: mock.register,- configureRecipient: mock.configure,- unwatch: mock.unwatch,- acknowledge: mock.acknowledge,- watch: async (callback: (event: PushEvent) => void) => {- await mock.watch(callback);- },- }),-}));--import { MaybePushNotificationRegistration } from './PushNotification';--beforeEach(() => {- vi.resetAllMocks();- localStorage.clear();- mock.loggedIn = true;- mock.watcher = undefined;- mock.watch.mockImplementation(- async (callback: (event: PushEvent) => void) => {- mock.watcher = callback;- }- );- mock.notifications = undefined;- mock.check.mockResolvedValue({ status: 'denied' });- mock.register.mockResolvedValue({ success: true, token: 'test-token' });- mock.configure.mockResolvedValue(undefined);- mock.unwatch.mockResolvedValue(undefined);- mock.recipient.mockResolvedValue('macro|[email protected]');- mock.registerDevice.mockResolvedValue({ isErr: () => false });- mock.unregisterDevice.mockResolvedValue({ isErr: () => false });-});-afterEach(() => {- cleanup();- vi.useRealTimers();-});--async function mount() {- render(() => (- <MaybePushNotificationRegistration>- <div />- </MaybePushNotificationRegistration>- ));- await vi.waitFor(() => expect(mock.watcher).toBeDefined());- // Let the launch sync (permission denied -> receiver disarmed) finish- // before starting a new action.- await vi.waitFor(() => expect(mock.configure).toHaveBeenCalledWith(null));- expect(mock.check).toHaveBeenCalledTimes(1);- expect(mock.configure).toHaveBeenCalledTimes(1);- mock.configure.mockClear();-}--describe('Android push lifecycle', () => {- it('listens before registration and navigates only on taps', async () => {- await mount();- expect(mock.registerDevice).not.toHaveBeenCalled();- mock.watcher?.({- type: 'BACKGROUND_DELIVERY',- payload: { notificationId: 'id' },- });- expect(mock.navigate).not.toHaveBeenCalled();- mock.watcher?.({- type: 'BACKGROUND_TAP',- payload: { notificationId: 'id' },- deliveryId: 'delivery-id',- });- expect(mock.navigate).toHaveBeenCalledWith('id');- expect(mock.acknowledge).toHaveBeenCalledWith('delivery-id');- });-- it('shares an in-flight watcher and retries failure so taps still navigate', async () => {- vi.useFakeTimers();- let fail!: (error: Error) => void;- mock.watch.mockImplementationOnce(- () =>- new Promise((_, reject) => {- fail = reject;- })- );- render(() => (- <MaybePushNotificationRegistration>- <div />- </MaybePushNotificationRegistration>- ));- await vi.advanceTimersByTimeAsync(0);- mock.check.mockResolvedValue({ status: 'granted' });- let finished = false;- async function syncRegistration() {- await mock.lifecycle!.syncRegistration();- finished = true;- }- const registration = syncRegistration();- await vi.advanceTimersByTimeAsync(0);- expect(mock.watch).toHaveBeenCalledOnce();- expect(finished).toBe(false);- fail(new Error('Transient bridge failure'));- await registration;- await vi.advanceTimersByTimeAsync(1000);- expect(mock.watch).toHaveBeenCalledTimes(2);- mock.watcher?.({- type: 'BACKGROUND_TAP',- payload: { notificationId: 'id' },- deliveryId: 'tap',- });- expect(mock.navigate).toHaveBeenCalledWith('id');- expect(mock.acknowledge).toHaveBeenCalledWith('tap');- await vi.advanceTimersByTimeAsync(5000);- expect(mock.watch).toHaveBeenCalledTimes(2);- });-- it.each([false, true])(- 'does not retry a failed watcher after disposal (failure pending: %s)',- async (pending) => {- vi.useFakeTimers();- let fail!: (error: Error) => void;- mock.watch.mockImplementationOnce(- () =>- new Promise((_, reject) => {- fail = reject;- })- );- const { unmount } = render(() => (- <MaybePushNotificationRegistration>- <div />- </MaybePushNotificationRegistration>- ));- await vi.advanceTimersByTimeAsync(0);- if (pending) unmount();- fail(new Error('Transient bridge failure'));- await vi.advanceTimersByTimeAsync(0);- if (!pending) unmount();- await vi.advanceTimersByTimeAsync(5000);- expect(mock.watch).toHaveBeenCalledOnce();- }- );-- it('binds the native receiver only after backend registration succeeds', async () => {- await mount();- mock.check.mockResolvedValue({ status: 'granted' });- await mock.lifecycle?.syncRegistration();- expect(mock.registerDevice).toHaveBeenCalledWith({- deviceType: 'android',- token: 'test-token',- });- expect(mock.configure).toHaveBeenCalledWith('macro|[email protected]');- });-- it('cannot re-enable the old recipient when registration finishes after logout', async () => {- await mount();- mock.check.mockResolvedValue({ status: 'granted' });- let complete!: (value: { isErr: () => boolean }) => void;- mock.registerDevice.mockImplementation(- () =>- new Promise((resolve) => {- complete = resolve;- })- );- const syncing = expect(mock.lifecycle!.syncRegistration()).rejects.toThrow(- 'push device registration did not complete'- );- await vi.waitFor(() => expect(mock.registerDevice).toHaveBeenCalled());- const logout = mock.lifecycle!.unregisterForLogout();- await vi.waitFor(() => expect(mock.configure).toHaveBeenCalledWith(null));- mock.loggedIn = false;- complete({ isErr: () => false });- await Promise.all([syncing, logout]);- expect(mock.configure.mock.calls).toEqual([[null]]);- expect(mock.unregisterDevice).toHaveBeenCalledWith({- deviceType: 'android',- token: 'test-token',- });- expect(mock.unregisterDevice.mock.invocationCallOrder[0]).toBeGreaterThan(- mock.registerDevice.mock.invocationCallOrder[0]- );- });-- it.each(['logout', 'opt-out'])(- 'disarms a native configure that completes during %s',- async (action) => {- await mount();- mock.check.mockResolvedValue({ status: 'granted' });- let complete!: () => void;- let nativeRecipient: string | null = null;- mock.configure.mockImplementation(async (recipient: string | null) => {- if (recipient !== null) {- await new Promise<void>((resolve) => {- complete = resolve;- });- }- nativeRecipient = recipient;- });- const syncing = expect(- mock.lifecycle!.syncRegistration()- ).rejects.toThrow('push device registration did not complete');- await vi.waitFor(() => expect(complete).toBeDefined());- const disabling =- action === 'logout'- ? mock.lifecycle!.unregisterForLogout()- : mock.notifications!.unregisterNotifications();- if (action === 'logout') mock.loggedIn = false;- complete();- await Promise.all([syncing, disabling]);- expect(nativeRecipient).toBeNull();- expect(mock.configure).toHaveBeenLastCalledWith(null);- expect(mock.unregisterDevice).toHaveBeenCalledWith({- deviceType: 'android',- token: 'test-token',- });- }- );-- it.each(['backend', 'native'])(- 'keeps the new account registered after stale %s completion',- async (pendingStep) => {- await mount();- mock.check.mockResolvedValue({ status: 'granted' });- let complete!: () => void;- let nativeRecipient: string | null = null;- let backendRegistered = false;- const delayed = async () => {- await new Promise<void>((resolve) => {- complete = resolve;- });- };- mock.registerDevice.mockImplementation(async () => {- if (- pendingStep === 'backend' &&- mock.registerDevice.mock.calls.length === 1- )- await delayed();- backendRegistered = true;- return { isErr: () => false };- });- mock.unregisterDevice.mockImplementation(async () => {- backendRegistered = false;- return { isErr: () => false };- });- mock.configure.mockImplementation(async (recipient: string | null) => {- if (pendingStep === 'native' && recipient === 'macro|[email protected]')- await delayed();- nativeRecipient = recipient;- });- const oldSync = expect(- mock.lifecycle!.syncRegistration()- ).rejects.toThrow('push device registration did not complete');- await vi.waitFor(() => expect(complete).toBeDefined());- const logout = mock.lifecycle!.unregisterForLogout();- // Model a new login after logout's network timeout. The token is shared.- mock.recipient.mockResolvedValue('macro|[email protected]');- const newSync = mock.lifecycle!.syncRegistration();- complete();- await Promise.all([oldSync, logout, newSync]);- expect(backendRegistered).toBe(true);- expect(nativeRecipient).toBe('macro|[email protected]');- expect(mock.configure).toHaveBeenLastCalledWith('macro|[email protected]');- expect(mock.registerDevice).toHaveBeenCalledTimes(2);- expect(mock.registerDevice.mock.invocationCallOrder[1]).toBeGreaterThan(- Math.max(...mock.unregisterDevice.mock.invocationCallOrder)- );- }- );-- it('disables native display when permission is revoked', async () => {- await mount();- mock.check.mockResolvedValue({ status: 'granted' });- await mock.lifecycle?.syncRegistration();- mock.configure.mockClear();- mock.check.mockResolvedValue({ status: 'denied' });- await mock.lifecycle?.syncRegistration();- expect(mock.configure).toHaveBeenCalledWith(null);- });-- it('suppresses websocket local notifications after remote push registration', async () => {- await mount();- mock.check.mockResolvedValue({ status: 'granted' });- await mock.lifecycle?.syncRegistration();- await mock.notifications!.showNotification({- title: 'Duplicate message',- options: { body: 'Body' },- });- expect(mock.localShow).not.toHaveBeenCalled();- });-});diff --git a/apps/web/src/lib/tauri/PushNotification.tsx b/apps/web/src/lib/tauri/PushNotification.tsxindex 4ef4d6fc65..093dd642dc 100644--- a/apps/web/src/lib/tauri/PushNotification.tsx+++ b/apps/web/src/lib/tauri/PushNotification.tsx@@ -311,7 +311,9 @@ function usePushNotifications(createEffect(() => {if (!onPushNotification) return;- if (deviceType === 'ios' && !registrationResult()?.success) return;+ // Delivered notifications can be tapped before APNs registration finishes+ // or when registration fails. Attach the listener so native buffered taps+ // can navigate independently of acquiring a token for future pushes.void startWatch();});diff --git a/apps/web/tauri/src-tauri/src/lib.rs b/apps/web/tauri/src-tauri/src/lib.rsindex b9d835fd29..4ec96a071f 100644--- a/apps/web/tauri/src-tauri/src/lib.rs+++ b/apps/web/tauri/src-tauri/src/lib.rs@@ -168,7 +168,6 @@ pub fn run() {{builder = builder.plugin(tauri_plugin_auth::init())- .plugin(tauri_plugin_notifications::init()).plugin(tauri_plugin_virtual_keyboard::init()).plugin(tauri_plugin_edit_menu::init()).plugin(tauri_plugin_input_accessory::init())@@ -228,6 +227,14 @@ pub fn run() {.with_auto_update(cfg!(feature = "auto_apply_update") && !recording),);+ #[cfg(target_os = "ios")]+ {+ // Both notification plugins assign UNUserNotificationCenter.delegate.+ // Initialize push last: the local-notification delegate ignores remote+ // pushes, so leaving it installed drops taps before frontend navigation.+ builder = builder.plugin(tauri_plugin_notifications::init());+ }+#[cfg(mobile)]{// register mobile specific pluginsdiff --git a/apps/web/tests/native/ios/README.md b/apps/web/tests/native/ios/README.mdindex 7be48b5915..dfaf17da76 100644--- a/apps/web/tests/native/ios/README.md+++ b/apps/web/tests/native/ios/README.md@@ -78,6 +78,53 @@ Apple's associated-domain routing. It intentionally avoids authenticated writes.For iPad, dismiss the existing `Optimized for iPhone` notice manually if itobscures screenshots; do not interpret it as a scene-lifecycle error.+## Thread reply push notifications++Run a native debug build with automatic bundle updates disabled. For a separate+Vite server used by the native app, set `MACRO_DEV_PROXY=false` (or run it through+the Tauri CLI); the browser-only hosted API proxy cannot be fetched through the+native HTTP plugin from `tauri://localhost`.++Sign in as the notification recipient. Use a real thread reply notification that+the account can read and record its notification ID, channel ID, parent message+ID, and reply ID. Choose a reply outside the collapsed thread preview. A made-up+notification ID can check bridge delivery but cannot verify message navigation.++To inject the push without depending on APNs transport, save this payload to a+temporary `.apns` file, replacing `<notification-id>` with the real ID:++```json+{+ "aps": {+ "alert": {+ "title": "Thread reply navigation test",+ "body": "Open the target reply"+ },+ "sound": "default"+ },+ "notificationId": "<notification-id>"+}+```++Send it with `xcrun simctl push <udid> com.macro.app.prod <payload.apns>`.+Grant notification permission, background the app, open Notification Center,+and tap the notification. Verify the correct channel opens, the parent thread+expands, and the specific reply is visible. Repeat after terminating the app and+with an in-app foreground banner. Simulator injection tests OS presentation,+delegate delivery, and app navigation; separately verify real APNs delivery on+a physical device.++If IDB taps do not activate the Notification Center card, use its swipe-to-open+action to exercise the same native notification response callback.++Both the common local-notification plugin and the iOS push plugin set+`UNUserNotificationCenter.delegate`. The push plugin must initialize after the+local plugin, whose delegate ignores remote notifications. Check native delivery+as well as frontend routing when investigating a tap that does nothing.+The frontend listener must also attach before token registration succeeds:+already-delivered notifications still need to navigate when APNs registration+is pending or fails, including the simulator's registration timeout.+## Release checks still required- iOS 26 and physical iPhone/iPad regressions; iOS 27 simulator coverage alonediff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.mdindex 85ec31258c..fffcf7f626 100644--- a/docs/AGENT_GUIDE/channels.md+++ b/docs/AGENT_GUIDE/channels.md@@ -438,6 +438,14 @@ notifications, and switching channels while notifications load. Loading thischannel's notification edge must not delay its messages or activate the globalGraphQL notification feed.+On native iOS, tapping a thread reply push in Notification Center or on the lock+screen should open its channel, expand the parent thread, and reveal the actual+reply. Verify with the app backgrounded and after terminating it. Use an older+thread with a reply hidden by the collapsed preview so opening only the channel+or parent message cannot satisfy the check. See the+[native notification regression procedure](../../apps/web/tests/native/ios/README.md#thread-reply-push-notifications)+for simulator setup.+The `[data-channel-scroll]` element is the scroll surface. Its virtualized rows arekeyed by message ID; offscreen rows are normally absent from the DOM.