feat(chat): unlock history after payment

This commit is contained in:
2026-06-29 10:53:52 +08:00
parent 58cd2a7545
commit b7779878cf
15 changed files with 591 additions and 18 deletions
@@ -4,6 +4,7 @@ import { ChatSendResponse } from "@/data/dto/chat/chat_send_response";
import type { ChatState } from "@/stores/chat/chat-state";
import {
applyHttpSendOutput,
countLockedHistoryMessages,
localMessagesToUi,
sendResponseToUiMessage,
} from "@/stores/chat/chat-machine.helpers";
@@ -43,6 +44,11 @@ function makeChatState(overrides: Partial<ChatState> = {}): ChatState {
hasMore: true,
historyOffset: 0,
historyLoaded: true,
paymentUnlockPending: false,
unlockHistoryPromptVisible: false,
lockedHistoryCount: 0,
isUnlockingHistory: false,
unlockHistoryError: null,
...overrides,
};
}
@@ -231,3 +237,40 @@ describe("localMessagesToUi", () => {
expect(message.imagePaywalled).toBeUndefined();
});
});
describe("countLockedHistoryMessages", () => {
it("counts only unlockable locked AI messages", () => {
expect(
countLockedHistoryMessages([
{
content: "",
isFromAI: true,
date: "2026-06-29",
locked: true,
lockReason: "private_message",
},
{
content: "",
isFromAI: true,
date: "2026-06-29",
locked: true,
lockReason: "voice_message",
},
{
content: "",
isFromAI: true,
date: "2026-06-29",
locked: true,
lockReason: "daily_limit",
},
{
content: "user text",
isFromAI: false,
date: "2026-06-29",
locked: true,
lockReason: "private_message",
},
]),
).toBe(2);
});
});