2026-01-13 14:49:19 +01:00

36 lines
1.4 KiB
TypeScript

import type { Event } from 'nostr-tools'
import type { Article } from '@/types/nostr'
import { createSubscription } from '@/types/nostr-tools-extended'
import { parseArticleFromEvent } from '../nostrEventParsing'
import { parsePresentationEvent } from '../articlePublisherHelpersPresentation'
import { buildTagFilter } from '../nostrTagSystem'
import { MIN_EVENT_DATE, PLATFORM_SERVICE } from '../platformConfig'
import { getPrimaryRelaySync } from '../config'
export function createArticleSubscription(params: {
pool: import('nostr-tools').SimplePool
limit: number
}): ReturnType<typeof createSubscription> {
const filters = [
{ ...buildTagFilter({ type: 'publication', service: PLATFORM_SERVICE }), since: MIN_EVENT_DATE, limit: params.limit },
{ ...buildTagFilter({ type: 'author', service: PLATFORM_SERVICE }), since: MIN_EVENT_DATE, limit: params.limit },
]
return createSubscription(params.pool, [getPrimaryRelaySync()], filters)
}
export async function parseArticleOrPresentationFromEvent(event: Event): Promise<Article | null> {
try {
let article = await parseArticleFromEvent(event)
if (!article) {
const presentation = await parsePresentationEvent(event)
if (presentation) {
article = presentation
}
}
return article
} catch (parseError) {
console.error('[NostrService] Error parsing article:', parseError)
return null
}
}