diff --git a/lib/notifications.server.ts b/lib/notifications.server.ts index afcee5d8..a64a7a43 100644 --- a/lib/notifications.server.ts +++ b/lib/notifications.server.ts @@ -160,6 +160,27 @@ export async function sendNotification(params: { const appUrl = process.env.NEXT_PUBLIC_APP_URL ?? "https://plotlink.xyz"; +/** + * Notify all users with enabled notifications about a new storyline. + * Called from the backfill cron when a new storyline is first indexed. + */ +export async function notifyNewStoryline( + storylineId: number, + title: string, + author: string, +): Promise { + const tokens = await getEnabledTokens(); + if (tokens.length === 0) return; + + await sendNotification({ + notificationId: `pl-new-storyline-${storylineId}`, + title: "New story published", + body: `"${title}" by ${author} is now on PlotLink`, + targetUrl: `${appUrl}/story/${storylineId}`, + tokens, + }); +} + /** * Notify all users with enabled notifications about a new plot. * Called from the backfill cron when a new plot is indexed. diff --git a/src/app/api/cron/backfill/route.ts b/src/app/api/cron/backfill/route.ts index 22ff0ff1..72e34282 100644 --- a/src/app/api/cron/backfill/route.ts +++ b/src/app/api/cron/backfill/route.ts @@ -7,7 +7,7 @@ import { STORY_FACTORY } from "../../../../../lib/contracts/constants"; import { hashContent } from "../../../../../lib/content"; import { detectWriterType } from "../../../../../lib/contracts/erc8004"; import { reconcileStorylinePlotCount } from "../../../../../lib/reconcile"; -import { notifyNewPlot } from "../../../../../lib/notifications.server"; +import { notifyNewPlot, notifyNewStoryline } from "../../../../../lib/notifications.server"; import type { Database } from "../../../../../lib/supabase"; const IPFS_GATEWAY = "https://ipfs.filebase.io/ipfs/"; @@ -164,9 +164,9 @@ export async function GET(req: Request) { storylinesInserted++; if (result.genesisPlotFailed) failures++; else { - // Notify users about the new story - const args = decoded.args as { storylineId: bigint; title: string }; - notifyNewPlot(Number(args.storylineId), args.title, 0).catch(() => {}); + // Notify users about the new storyline + const args = decoded.args as { storylineId: bigint; title: string; writer: `0x${string}` }; + notifyNewStoryline(Number(args.storylineId), args.title, args.writer).catch(() => {}); } } else if (decoded.eventName === "PlotChained") { const failed = await processPlotChained(