2026-06-22 23:06:00 +00:00
|
|
|
import {derived} from "svelte/store"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {APP_DATA, tagSpec, tagValues} from "@welshman/util"
|
|
|
|
|
import {AppData} from "@welshman/domain"
|
|
|
|
|
import {Domain} from "@welshman/app"
|
|
|
|
|
import {app} from "@app/core"
|
2026-06-23 23:30:54 +00:00
|
|
|
import {deriveRelaySignedEvents} from "@app/repository"
|
2026-06-22 23:06:00 +00:00
|
|
|
|
|
|
|
|
// NIP-78 app data published by the relay's self key. Each featured entry is a
|
|
|
|
|
// ["content", <value>] tag (freeform text, intended to be a url or nevent).
|
|
|
|
|
export const FEATURED_CONTENT_D = "flotilla/featured-content"
|
|
|
|
|
|
|
|
|
|
export const deriveFeaturedContent = (url: string) =>
|
|
|
|
|
derived(
|
2026-06-23 23:30:54 +00:00
|
|
|
deriveRelaySignedEvents(url, [{kinds: [APP_DATA], "#d": [FEATURED_CONTENT_D]}]),
|
2026-07-28 16:16:26 +00:00
|
|
|
([event]) => tagValues(tagSpec("content"), event?.tags ?? []),
|
2026-06-22 23:06:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Publish the featured content list by asking the relay to sign it with its self
|
|
|
|
|
// key (the unofficial NIP-86 "signevent" method).
|
2026-07-28 16:16:26 +00:00
|
|
|
export const setFeaturedContent = async (url: string, content: string[]) => {
|
|
|
|
|
const tags = content
|
|
|
|
|
.map(value => value.trim())
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
.map(value => ["content", value])
|
|
|
|
|
|
|
|
|
|
const writer = app
|
|
|
|
|
.get()
|
|
|
|
|
.use(Domain)
|
|
|
|
|
.writer(AppData)
|
|
|
|
|
.forceRelays(url)
|
|
|
|
|
.setIdentifier(FEATURED_CONTENT_D)
|
|
|
|
|
.addTags(...tags)
|
|
|
|
|
|
|
|
|
|
const command = await app.get().use(Domain).command(writer)
|
|
|
|
|
|
|
|
|
|
return command.publishAsRelay(url)
|
|
|
|
|
}
|