2026-06-22 23:06:00 +00:00
|
|
|
import {derived} from "svelte/store"
|
2026-09-17 17:26:40 +00:00
|
|
|
import {APP_DATA, relay, sortEventsDesc, tagSpec, tagValues} from "@welshman/util"
|
2026-07-28 16:16:26 +00:00
|
|
|
import {AppData} from "@welshman/domain"
|
2026-09-17 17:26:40 +00:00
|
|
|
import {Relays, publish} from "@welshman/app"
|
|
|
|
|
import {command, fromApp, relays, writer} from "@app/core"
|
|
|
|
|
import {deriveEventsForUrl} from "@app/repository"
|
2026-06-22 23:06:00 +00:00
|
|
|
|
2026-09-17 17:26:40 +00:00
|
|
|
// NIP-78 app data published by the space's owner, the pubkey its NIP-11 document names. Each
|
|
|
|
|
// featured entry is a ["content", <value>] tag (freeform text, intended to be a url or nevent).
|
2026-06-22 23:06:00 +00:00
|
|
|
export const FEATURED_CONTENT_D = "flotilla/featured-content"
|
|
|
|
|
|
|
|
|
|
export const deriveFeaturedContent = (url: string) =>
|
|
|
|
|
derived(
|
2026-09-17 17:26:40 +00:00
|
|
|
[
|
|
|
|
|
fromApp($app => $app.use(Relays).one(url)),
|
|
|
|
|
deriveEventsForUrl(url, [{kinds: [APP_DATA], "#d": [FEATURED_CONTENT_D]}]),
|
|
|
|
|
],
|
|
|
|
|
([$relay, $events]) => {
|
|
|
|
|
const [event] = sortEventsDesc($events.filter(e => e.pubkey === $relay?.pubkey))
|
|
|
|
|
|
|
|
|
|
return tagValues(tagSpec("content"), event?.tags ?? [])
|
|
|
|
|
},
|
2026-06-22 23:06:00 +00:00
|
|
|
)
|
|
|
|
|
|
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])
|
|
|
|
|
|
2026-09-17 17:26:40 +00:00
|
|
|
const eventWriter = writer(AppData)
|
2026-07-28 16:16:26 +00:00
|
|
|
.setIdentifier(FEATURED_CONTENT_D)
|
2026-09-17 17:26:40 +00:00
|
|
|
.setProtected(await relays.get().hasNip(url, 70))
|
|
|
|
|
.forceRoutes(relay(url))
|
2026-07-28 16:16:26 +00:00
|
|
|
.addTags(...tags)
|
|
|
|
|
|
2026-09-17 17:26:40 +00:00
|
|
|
return command(eventWriter).then(publish)
|
2026-07-28 16:16:26 +00:00
|
|
|
}
|