import type { ReviewTip } from '@/types/nostr' import { objectCache } from './objectCache' import { parseObjectId } from './urlGenerator' export async function getReviewTipById(reviewTipId: string, _timeoutMs: number = 5000): Promise { const parsed = parseObjectId(reviewTipId) const hash = parsed.hash ?? reviewTipId // Read only from IndexedDB cache const cached = await objectCache.get('review_tip', hash) if (cached) { return cached as ReviewTip } // Also try by ID if hash lookup failed const cachedById = await objectCache.getById('review_tip', reviewTipId) if (cachedById) { return cachedById as ReviewTip } // Not found in cache - return null (no network request) return null } export async function getReviewTipsForArticle(articleId: string, _timeoutMs: number = 5000): Promise { // Read only from IndexedDB cache const allReviewTips = await objectCache.getAll('review_tip') const reviewTips = allReviewTips as ReviewTip[] // Filter by articleId const articleReviewTips = reviewTips.filter((tip) => tip.articleId === articleId) // Sort by creation date descending return articleReviewTips.sort((a, b) => b.createdAt - a.createdAt) } export async function getReviewTipsForReview(reviewId: string, _timeoutMs: number = 5000): Promise { // Read only from IndexedDB cache const allReviewTips = await objectCache.getAll('review_tip') const reviewTips = allReviewTips as ReviewTip[] // Filter by reviewId const reviewReviewTips = reviewTips.filter((tip) => tip.reviewId === reviewId) // Sort by creation date descending return reviewReviewTips.sort((a, b) => b.createdAt - a.createdAt) }