import { getSponsoringByAuthor } from './sponsoringQueries' import type { Article } from '@/types/nostr' /** * Get total sponsoring for an author by their pubkey * Calculates from cache (sponsoring queries) instead of tags */ export async function getAuthorSponsoring(pubkey: string): Promise { try { const sponsoringList = await getSponsoringByAuthor(pubkey, 5000) // Sum all sponsoring amounts for this author return sponsoringList.reduce((total, sponsoring) => total + sponsoring.amount, 0) } catch (error) { console.error('Error calculating author sponsoring from cache:', error) return 0 } } /** * Get sponsoring for multiple authors (for sorting) * Returns a map of pubkey -> total sponsoring */ export function getAuthorsSponsoring(pubkeys: string[]): Map { const sponsoringMap = new Map() // For now, we'll extract sponsoring from articles that are already loaded // In a real implementation, we'd query all presentation articles // For performance, we'll use the sponsoring from the article's totalSponsoring field pubkeys.forEach((pubkey) => { sponsoringMap.set(pubkey, 0) }) return sponsoringMap } /** * Get sponsoring from an article (if it's a presentation article) */ export function getSponsoringFromArticle(article: Article): number { if (article.isPresentation && article.totalSponsoring !== undefined) { return article.totalSponsoring } return 0 }