Skip to content

Commit a8799b6

Browse files
committed
fix(mobile): preserve snooze when undoing unpin
1 parent 93bbea6 commit a8799b6

3 files changed

Lines changed: 60 additions & 15 deletions

File tree

‎apps/mobile/src/features/home/useThreadListActions.test.ts‎

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,44 @@ describe("thread action undo", () => {
368368
});
369369
});
370370

371-
it("restores an unpinned thread's previous position", async () => {
372-
const thread = makeThread({ pinnedAt: "2026-09-02T00:00:00.000Z", pinOrderKey: "m" });
371+
it.each([null, "2099-01-01T09:00:00.000Z", "2000-01-01T09:00:00.000Z"])(
372+
"restores an unpinned thread's previous position and unexpired snooze (%s)",
373+
async (snoozedUntil) => {
374+
const thread = makeThread({
375+
pinnedAt: "2026-09-02T00:00:00.000Z",
376+
pinOrderKey: "m",
377+
snoozedUntil,
378+
});
379+
await useThreadListActions().unpinThread(thread);
380+
expect(readThreadUndoNotice()?.action).toBe("Unpinned");
381+
await readThreadUndoNotice()!.undo();
382+
const restoresSnooze = snoozedUntil != null && Date.parse(snoozedUntil) > Date.now();
383+
expect(state.requests.map(({ action }) => action)).toEqual(
384+
restoresSnooze ? ["unpin", "pin", "snooze"] : ["unpin", "pin"],
385+
);
386+
expect(state.requests[1]).toMatchObject({
387+
action: "pin",
388+
input: { threadId: thread.id, orderKey: "m" },
389+
});
390+
if (restoresSnooze) {
391+
expect(state.requests[2]).toMatchObject({
392+
action: "snooze",
393+
environmentId: thread.environmentId,
394+
input: { threadId: thread.id, snoozedUntil },
395+
});
396+
}
397+
},
398+
);
399+
400+
it("does not restore snooze if undoing an unpin fails", async () => {
401+
const thread = makeThread({
402+
pinnedAt: "2026-09-02T00:00:00.000Z",
403+
snoozedUntil: "2099-01-01T09:00:00.000Z",
404+
});
373405
await useThreadListActions().unpinThread(thread);
374-
expect(readThreadUndoNotice()?.action).toBe("Unpinned");
406+
state.failedAction = "pin";
375407
await readThreadUndoNotice()!.undo();
376-
expect(state.requests.at(-1)).toMatchObject({
377-
action: "pin",
378-
input: { threadId: thread.id, orderKey: "m" },
379-
});
408+
expect(state.requests.map(({ action }) => action)).toEqual(["unpin", "pin"]);
380409
});
381410

382411
it("invalidates a retained undo when another hook pins the thread", async () => {

‎apps/web/src/hooks/useThreadActions.undo.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ afterEach(() => {
108108
});
109109

110110
describe("unpin Undo", () => {
111+
it("restores the original snooze after restoring the pin", async () => {
112+
threadShell.pinnedAt = "2026-01-01T00:00:00.000Z";
113+
threadShell.snoozedUntil = "2030-01-01T09:00:00.000Z";
114+
await useThreadActions().unpinThread(target);
115+
await currentUndo()();
116+
expect(commands.pin).toHaveBeenCalledExactlyOnceWith({
117+
environmentId: target.environmentId,
118+
input: { threadId: target.threadId, orderKey: "a0" },
119+
});
120+
expect(commands.snooze).toHaveBeenCalledExactlyOnceWith({
121+
environmentId: target.environmentId,
122+
input: { threadId: target.threadId, snoozedUntil: threadShell.snoozedUntil },
123+
});
124+
expect(commands.pin.mock.invocationCallOrder[0]).toBeLessThan(
125+
commands.snooze.mock.invocationCallOrder[0]!,
126+
);
127+
});
128+
111129
it("ignores an old notice across hook instances and still restores the latest unpin", async () => {
112130
const sidebar = useThreadActions();
113131
const header = useThreadActions();

‎packages/client-runtime/src/state/threadUndo.ts‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ export function planThreadUndo(
5656
action: "pin",
5757
...(thread?.pinOrderKey != null ? { orderKey: thread.pinOrderKey } : {}),
5858
};
59-
if (action === "unpin") return [pin];
60-
// Settling clears both pin and snooze on the server; restore them after promotion.
61-
return [
62-
{ action: "unsettle" },
63-
...(thread?.pinnedAt != null ? [pin] : []),
64-
...(thread?.snoozedUntil != null
59+
// Pinning clears snooze on the server; restore it after restoring pin placement.
60+
const snooze =
61+
thread?.snoozedUntil != null
6562
? [{ action: "snooze" as const, snoozedUntil: thread.snoozedUntil }]
66-
: []),
67-
];
63+
: [];
64+
if (action === "unpin") return [pin, ...snooze];
65+
return [{ action: "unsettle" }, ...(thread?.pinnedAt != null ? [pin] : []), ...snooze];
6866
}
6967

7068
export async function executeThreadUndo<Result>(

0 commit comments

Comments
 (0)