89 lines
3.3 KiB
TypeScript
89 lines
3.3 KiB
TypeScript
export const RECTIFICATION_OPENING_COMPOSER_PLACEHOLDER = "正在打开生时校正…";
|
|
export const RECTIFICATION_REOPEN_LABEL = "重新打开生时校正";
|
|
export const SESSION_NOT_CONSULTATION_CODE = "session_not_consultation";
|
|
|
|
export function isRectificationChatSession(
|
|
session: { sessionType?: string } | null | undefined,
|
|
): boolean {
|
|
return session?.sessionType === "birth_time_rectification";
|
|
}
|
|
|
|
/** First non-rectification session, else the first session, else empty. */
|
|
export function fallbackSessionId<T extends { id: string; sessionType: string }>(
|
|
sessions: readonly T[],
|
|
): string {
|
|
return sessions.find((session) => session.sessionType !== "birth_time_rectification")?.id
|
|
?? sessions[0]?.id
|
|
?? "";
|
|
}
|
|
|
|
export function consultSendBlockedByRectificationSession(
|
|
session: { sessionType?: string } | null | undefined,
|
|
): boolean {
|
|
return isRectificationChatSession(session);
|
|
}
|
|
|
|
/** Empty active session with only rectification rows still occupies the ordinary composer. */
|
|
export function composerLocksAsRectification(
|
|
activeSession: { sessionType?: string } | null | undefined,
|
|
sessions: readonly { sessionType: string }[],
|
|
): boolean {
|
|
if (isRectificationChatSession(activeSession)) return true;
|
|
if (activeSession) return false;
|
|
return sessions.some((session) => session.sessionType === "birth_time_rectification");
|
|
}
|
|
|
|
export function missingActiveSessionSendAction(
|
|
sessions: readonly { id: string; sessionType: string }[],
|
|
): { openSessionId: string } | { notice: string } {
|
|
const rectification = sessions.find((session) => session.sessionType === "birth_time_rectification");
|
|
if (rectification) return { openSessionId: rectification.id };
|
|
return { notice: "请先选一条对话,或点上方「新建对话」。" };
|
|
}
|
|
|
|
export function dropRectificationStoredPending<
|
|
S extends { sessionId: string },
|
|
T extends { id: string; sessionType: string },
|
|
>(
|
|
stored: S | null,
|
|
sessions: readonly T[],
|
|
): S | null {
|
|
if (!stored) return null;
|
|
const session = sessions.find((item) => item.id === stored.sessionId);
|
|
if (session?.sessionType === "birth_time_rectification") return null;
|
|
return stored;
|
|
}
|
|
|
|
export function ordinaryComposerPlaceholder(input: {
|
|
locked: boolean;
|
|
hasAccount: boolean;
|
|
profileComplete: boolean;
|
|
onboardingName: boolean;
|
|
presetMessageFinished: boolean;
|
|
creditsEmpty: boolean;
|
|
subjectDeleted?: boolean;
|
|
}): string {
|
|
if (input.locked) return RECTIFICATION_OPENING_COMPOSER_PLACEHOLDER;
|
|
if (input.subjectDeleted) return "这份资料已经删除,这段对话只能看";
|
|
if (!input.hasAccount) return "正在读取账户…";
|
|
if (!input.profileComplete) {
|
|
if (!input.onboardingName) return "请先完成上方资料";
|
|
return input.presetMessageFinished ? "输入你的称呼" : "Jyotisha 正在输入…";
|
|
}
|
|
if (input.creditsEmpty) return "余额不足,可在账户与点数中补充";
|
|
return "想聊什么都可以";
|
|
}
|
|
|
|
export function rectificationOrdinaryComposerReopen(input: {
|
|
activeRectificationSession: boolean;
|
|
error: string;
|
|
errorSessionId: string | null;
|
|
sessionId: string | undefined;
|
|
}): boolean {
|
|
if (!input.activeRectificationSession || !input.error || input.error === "profile_incomplete") {
|
|
return false;
|
|
}
|
|
if (!input.sessionId) return true;
|
|
return !input.errorSessionId || input.errorSessionId === input.sessionId;
|
|
}
|