fix(chat): migrate legacy character cache identities
This commit is contained in:
@@ -5,6 +5,7 @@ import { z } from "zod";
|
||||
import { StorageKeys } from "@/data/storage/storage_keys";
|
||||
import { ChatLockTypeSchema } from "@/data/schemas/chat";
|
||||
import { getCharacterById } from "@/data/constants/character";
|
||||
import { normalizeLegacyCharacterId } from "@/data/constants/character_id_aliases";
|
||||
import { Result } from "@/utils/result";
|
||||
import { SessionAsyncUtil } from "@/utils/session-storage";
|
||||
|
||||
@@ -138,7 +139,9 @@ export class NavigationStorage {
|
||||
await SessionAsyncUtil.remove(StorageKeys.pendingChatUnlock);
|
||||
return null;
|
||||
}
|
||||
if (value.characterId !== characterId) return null;
|
||||
if (value.characterId !== normalizeLegacyCharacterId(characterId)) {
|
||||
return null;
|
||||
}
|
||||
await SessionAsyncUtil.remove(StorageKeys.pendingChatUnlock);
|
||||
return value;
|
||||
}
|
||||
@@ -158,7 +161,9 @@ export class NavigationStorage {
|
||||
if (!value) {
|
||||
await SessionAsyncUtil.remove(StorageKeys.pendingChatUnlock);
|
||||
}
|
||||
return value?.characterId === characterId ? value : null;
|
||||
return value?.characterId === normalizeLegacyCharacterId(characterId)
|
||||
? value
|
||||
: null;
|
||||
}
|
||||
|
||||
static async hasPendingChatUnlock(characterId: string): Promise<boolean> {
|
||||
@@ -206,7 +211,9 @@ export class NavigationStorage {
|
||||
await SessionAsyncUtil.remove(StorageKeys.pendingChatPromotion);
|
||||
return null;
|
||||
}
|
||||
if (value.characterId !== characterId) return null;
|
||||
if (value.characterId !== normalizeLegacyCharacterId(characterId)) {
|
||||
return null;
|
||||
}
|
||||
await SessionAsyncUtil.remove(StorageKeys.pendingChatPromotion);
|
||||
return value;
|
||||
}
|
||||
@@ -250,7 +257,9 @@ export class NavigationStorage {
|
||||
await SessionAsyncUtil.remove(StorageKeys.pendingChatImageReturn);
|
||||
return null;
|
||||
}
|
||||
if (value.characterId !== characterId) return null;
|
||||
if (value.characterId !== normalizeLegacyCharacterId(characterId)) {
|
||||
return null;
|
||||
}
|
||||
await SessionAsyncUtil.remove(StorageKeys.pendingChatImageReturn);
|
||||
return value;
|
||||
}
|
||||
@@ -263,13 +272,15 @@ export class NavigationStorage {
|
||||
value: PendingChatUnlock | null,
|
||||
): PendingChatUnlock | null {
|
||||
if (!value || Date.now() - value.createdAt > MAX_AGE_MS) return null;
|
||||
if (!getCharacterById(value.characterId)) return null;
|
||||
const characterId = normalizeLegacyCharacterId(value.characterId);
|
||||
if (!getCharacterById(characterId)) return null;
|
||||
const promotion = value.promotion
|
||||
? NavigationStorage.parsePendingChatPromotion(value.promotion)
|
||||
: undefined;
|
||||
if (value.promotion && !promotion) return null;
|
||||
return PendingChatUnlockSchema.parse({
|
||||
...value,
|
||||
characterId,
|
||||
...(promotion ? { promotion } : {}),
|
||||
});
|
||||
}
|
||||
@@ -278,14 +289,20 @@ export class NavigationStorage {
|
||||
value: PendingChatImageReturn | null,
|
||||
): PendingChatImageReturn | null {
|
||||
if (!value || Date.now() - value.createdAt > MAX_AGE_MS) return null;
|
||||
return getCharacterById(value.characterId) ? value : null;
|
||||
const characterId = normalizeLegacyCharacterId(value.characterId);
|
||||
return getCharacterById(characterId)
|
||||
? PendingChatImageReturnSchema.parse({ ...value, characterId })
|
||||
: null;
|
||||
}
|
||||
|
||||
private static parsePendingChatPromotion(
|
||||
value: PendingChatPromotion | null,
|
||||
): PendingChatPromotion | null {
|
||||
if (!value || Date.now() - value.createdAt > MAX_AGE_MS) return null;
|
||||
return getCharacterById(value.characterId) ? value : null;
|
||||
const characterId = normalizeLegacyCharacterId(value.characterId);
|
||||
return getCharacterById(characterId)
|
||||
? PendingChatPromotionSchema.parse({ ...value, characterId })
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user