Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/notifications.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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.
Expand Down
8 changes: 4 additions & 4 deletions src/app/api/cron/backfill/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down Expand Up @@ -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(
Expand Down
Loading