diff --git a/apps/mobile/src/features/home/useThreadListActions.test.ts b/apps/mobile/src/features/home/useThreadListActions.test.ts index 9313aef299881..428bbaf7b9b38 100644 --- a/apps/mobile/src/features/home/useThreadListActions.test.ts +++ b/apps/mobile/src/features/home/useThreadListActions.test.ts @@ -31,6 +31,7 @@ const state = vi.hoisted(() => ({ buttons?: { text: string; onPress?: () => void }[]; }[], afterRequest: undefined as (() => void) | undefined, + heldActions: new Map>(), })); vi.mock("react", () => ({ @@ -145,6 +146,7 @@ vi.mock("../../state/threads", () => ({ input: { threadId: string; orderKey?: string }; }) => { state.requests.push({ action, ...request }); + await state.heldActions.get(action); if (!state.scopes.get(request.environmentId)?.has(AuthOrchestrationOperateScope)) { return AsyncResult.failure(Cause.fail(new Error("Thread operation denied"))); } @@ -200,6 +202,7 @@ beforeEach(() => { state.dialogs = []; state.alerts = []; state.afterRequest = undefined; + state.heldActions = new Map(); }); afterEach(() => { @@ -406,6 +409,23 @@ describe("thread action undo", () => { expect(state.archivedRefreshes).toEqual([primaryEnvironmentId]); }); + it("sends a different action while one is pending for the same thread", async () => { + const actions = useThreadListActions(); + const thread = makeThread(); + const settleResponse = Promise.withResolvers(); + state.heldActions.set("settle", settleResponse.promise); + + const pending = [ + actions.settleThread(thread), + actions.unsettleThread(thread), + actions.settleThread(thread), + ]; + settleResponse.resolve(); + + expect(await Promise.all(pending)).toEqual([true, true, true]); + expect(state.requests.map(({ action }) => action)).toEqual(["settle", "unsettle", "settle"]); + }); + it("restores pin placement and snooze after settling, only once", async () => { const thread = makeThread({ pinnedAt: "2026-09-02T00:00:00.000Z", diff --git a/apps/mobile/src/features/home/useThreadListActions.ts b/apps/mobile/src/features/home/useThreadListActions.ts index 3893569c6886d..9d44d971c1f03 100644 --- a/apps/mobile/src/features/home/useThreadListActions.ts +++ b/apps/mobile/src/features/home/useThreadListActions.ts @@ -91,7 +91,7 @@ function useThreadActionExecutor( const deleteMutation = useAtomCommand(threadEnvironment.delete, { reportFailure: false }); const settleMutation = useAtomCommand(threadEnvironment.settle, { reportFailure: false }); const unsettleMutation = useAtomCommand(threadEnvironment.unsettle, { reportFailure: false }); - const inFlightThreadKeys = useRef(new Set()); + const latestPendingActions = useRef(new Map()); const executeAction = async ( action: ThreadListAction, @@ -100,11 +100,13 @@ function useThreadActionExecutor( ) => { if (!checkThreadOperationPermission(thread, actionFailureTitle(action))) return false; const key = scopedThreadKey(thread.environmentId, thread.id); - if (inFlightThreadKeys.current.has(key)) { + // Drop only a repeat of the latest pending action; Settle → Un-settle → Settle must all send. + if (latestPendingActions.current.get(key)?.action === action) { return false; } - inFlightThreadKeys.current.add(key); + const pending = { action }; + latestPendingActions.current.set(key, pending); selectionHaptic(); const succeeded = await (async () => { if ( @@ -163,7 +165,7 @@ function useThreadActionExecutor( onCompleted?.(action, thread); return true; })(); - inFlightThreadKeys.current.delete(key); + if (latestPendingActions.current.get(key) === pending) latestPendingActions.current.delete(key); return succeeded; };