feat(chat): support ai photo viewing
This commit is contained in:
@@ -261,6 +261,54 @@ export const chatMachine = setup({
|
||||
return { messages, isReplyingAI: false };
|
||||
}),
|
||||
|
||||
appendAIImage: assign(({ context, event }) => {
|
||||
if (event.type !== "ChatImageReceived") return {};
|
||||
const messages = [...context.messages];
|
||||
const last = messages[messages.length - 1];
|
||||
|
||||
if (last?.isFromAI && !last.imageUrl) {
|
||||
messages[messages.length - 1] = {
|
||||
...last,
|
||||
imageUrl: event.imageUrl,
|
||||
};
|
||||
} else {
|
||||
messages.push({
|
||||
content: "",
|
||||
isFromAI: true,
|
||||
date: todayString(),
|
||||
imageUrl: event.imageUrl,
|
||||
});
|
||||
}
|
||||
|
||||
log.debug("[chat-machine] appendAIImage", {
|
||||
messagesCount: messages.length,
|
||||
hasMergedIntoLastMessage: Boolean(last?.isFromAI && !last.imageUrl),
|
||||
});
|
||||
|
||||
return {
|
||||
messages,
|
||||
paywallTriggered: false,
|
||||
paywallReason: null,
|
||||
paywallDetail: null,
|
||||
};
|
||||
}),
|
||||
|
||||
applyPaywallStatus: assign(({ event }) => {
|
||||
if (event.type !== "ChatPaywallStatusReceived") return {};
|
||||
if (!event.showUpgrade) {
|
||||
return {
|
||||
paywallTriggered: false,
|
||||
paywallReason: null,
|
||||
paywallDetail: null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
paywallTriggered: true,
|
||||
paywallReason: "photo_paywall",
|
||||
paywallDetail: null,
|
||||
};
|
||||
}),
|
||||
|
||||
incrementQuotaExceeded: assign(({ context }) => ({
|
||||
quotaExceededTrigger: context.quotaExceededTrigger + 1,
|
||||
})),
|
||||
@@ -546,6 +594,8 @@ export const chatMachine = setup({
|
||||
actions: "startUserSession",
|
||||
},
|
||||
ChatAISentenceReceived: { actions: "appendOrUpdateAISentence" },
|
||||
ChatImageReceived: { actions: "appendAIImage" },
|
||||
ChatPaywallStatusReceived: { actions: "applyPaywallStatus" },
|
||||
ChatWebSocketError: { actions: "appendSocketErrorMessage" },
|
||||
ChatWebSocketConnected: { actions: "setWsConnected" },
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user