Add chat gifts and relationship diary UI
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import type { TipOfferActionRequest } from "@/data/schemas/chat";
|
||||
import { chatApi } from "@/data/services/api/chat_api";
|
||||
|
||||
const SESSION_KEY_PREFIX = "cozsweet.tipOffer.session";
|
||||
|
||||
export function getTipOfferSessionId(characterId: string): string {
|
||||
const key = `${SESSION_KEY_PREFIX}.${characterId}`;
|
||||
try {
|
||||
const existing = globalThis.sessionStorage.getItem(key);
|
||||
if (existing) return existing;
|
||||
const created = createSessionId();
|
||||
globalThis.sessionStorage.setItem(key, created);
|
||||
return created;
|
||||
} catch {
|
||||
return createSessionId();
|
||||
}
|
||||
}
|
||||
|
||||
export function recordTipOfferAction(
|
||||
characterId: string,
|
||||
action: TipOfferActionRequest["action"],
|
||||
triggerSource: TipOfferActionRequest["triggerSource"],
|
||||
): void {
|
||||
void chatApi
|
||||
.recordTipOfferAction({
|
||||
characterId,
|
||||
sessionId: getTipOfferSessionId(characterId),
|
||||
action,
|
||||
triggerSource,
|
||||
})
|
||||
.catch(() => undefined);
|
||||
}
|
||||
|
||||
function createSessionId(): string {
|
||||
if (typeof globalThis.crypto?.randomUUID === "function") {
|
||||
return globalThis.crypto.randomUUID();
|
||||
}
|
||||
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 14)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user