refactor(chat): remove private unlock machine flow

This commit is contained in:
2026-06-26 19:17:29 +08:00
parent b6f18a1ef3
commit 1b73c3ac10
11 changed files with 27 additions and 302 deletions
@@ -3,7 +3,6 @@ import { createActor, fromCallback, fromPromise, waitFor } from "xstate";
import {
ChatSendResponse,
UnlockPrivateResponse,
type UiMessage,
} from "@/data/dto/chat";
import { chatMachine } from "@/stores/chat/chat-machine";
@@ -29,11 +28,6 @@ interface SendMessageHttpOutput {
reply: UiMessage | null;
}
interface UnlockPrivateOutput {
messageId: string;
response: UnlockPrivateResponse;
}
function makeChatSendResponse(): ChatSendResponse {
return ChatSendResponse.from({
reply: "",
@@ -56,7 +50,6 @@ function makeChatSendResponse(): ChatSendResponse {
function createTestChatMachine(
options: {
historyMessages?: UiMessage[];
unlockedContent?: string;
} = {},
) {
return chatMachine.provide({
@@ -97,21 +90,6 @@ function createTestChatMachine(
});
return () => undefined;
}),
unlockPrivateMessage: fromPromise<
UnlockPrivateOutput,
{ messageId: string }
>(async ({ input }) => ({
messageId: input.messageId,
response: UnlockPrivateResponse.from({
unlocked: true,
content: options.unlockedContent ?? "unlocked",
showUpgrade: false,
paywallTriggered: false,
privateFreeLimit: 0,
privateUsedToday: 0,
reason: "ok",
}),
})),
},
});
}
@@ -167,49 +145,6 @@ describe("chatMachine transitions", () => {
actor.stop();
});
it("unlocks a locked private message and clears unlocking state", async () => {
const actor = createActor(
createTestChatMachine({
historyMessages: [
{
id: "private-1",
content: "",
isFromAI: true,
date: "2026-06-25",
locked: true,
lockReason: "private_message",
isPrivate: true,
lockedPrivate: true,
privateMessageHint: "A private message is waiting.",
},
],
unlockedContent: "Here is the unlocked private message.",
}),
).start();
actor.send({ type: "ChatUserLogin", token: "token" });
await waitFor(actor, (snapshot) =>
snapshot.matches({ userSession: "ready" }),
);
actor.send({ type: "ChatUnlockPrivateMessage", messageId: "private-1" });
await waitFor(
actor,
(snapshot) =>
snapshot.context.messages[0]?.content ===
"Here is the unlocked private message.",
);
const [message] = actor.getSnapshot().context.messages;
expect(message.content).toBe("Here is the unlocked private message.");
expect(message.locked).toBe(false);
expect(message.lockedPrivate).toBe(false);
expect(message.privateMessageHint).toBeNull();
expect(actor.getSnapshot().context.unlockingPrivateMessageId).toBeNull();
actor.stop();
});
it("allows multiple messages to be queued without leaving ready state", async () => {
const actor = createActor(createTestChatMachine()).start();
@@ -278,21 +213,6 @@ describe("chatMachine transitions", () => {
});
return () => undefined;
}),
unlockPrivateMessage: fromPromise<
UnlockPrivateOutput,
{ messageId: string }
>(async ({ input }) => ({
messageId: input.messageId,
response: UnlockPrivateResponse.from({
unlocked: true,
content: "unlocked",
showUpgrade: false,
paywallTriggered: false,
privateFreeLimit: 0,
privateUsedToday: 0,
reason: "ok",
}),
})),
},
});
const actor = createActor(machine).start();