From 4dc82c0d5d50cba5b2fc30bb9bc6201f7756a0fb Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Tue, 24 Nov 2026 20:26:47 -0500 Subject: [PATCH] feat(npc-dialogue): mark contacts whose conversation has unread content The only unread signal was the NEW badge inside a conversation, so players had no way to see who had something to say. The directory now carries that signal: a cyan NEW chip on the card for any contact whose offered conversation has a node this player has never read. Unread is derived from the per-node read markers that already existed. Two gates run first so the chip never lies: the contact must have canMessage true, and the loader resolves the offered conversation with the same selectDialogueForUser gate the contact page uses (testing conversations filtered by dialogueVisibleTo). Cost is two queries for the whole directory rather than one per card. A branch added after a player finished a conversation brings the chip back, which is the point; a partially explored conversation stays marked until every branch is read. Measured on the live directory: three contacts chipped (the two with canMessage and unread flows, plus a seeded probe on a third), the probe's chip cleared after all its nodes were read, and a canMessage:false contact never chipped. Pure derivation covered by 6 tests. --- .../(frontend)/personnel/contacts/page.tsx | 16 +- src/components/frontend/personnel/NpcCard.tsx | 18 +- .../frontend/personnel/NpcDirectory.tsx | 7 +- src/lib/npc-dialogue/AGENTS.md | 24 +++ src/lib/npc-dialogue/unread.ts | 154 ++++++++++++++++++ tests/int/npc-dialogue-unread.int.spec.ts | 51 ++++++ 6 files changed, 265 insertions(+), 5 deletions(-) create mode 100644 src/lib/npc-dialogue/unread.ts create mode 100644 tests/int/npc-dialogue-unread.int.spec.ts diff --git a/src/app/(frontend)/personnel/contacts/page.tsx b/src/app/(frontend)/personnel/contacts/page.tsx index 3f89c24d..b7cbbda6 100644 --- a/src/app/(frontend)/personnel/contacts/page.tsx +++ b/src/app/(frontend)/personnel/contacts/page.tsx @@ -4,6 +4,8 @@ import { headers as nextHeaders } from "next/headers"; import type { GameNpc } from "@/payload-types"; import { UsersIcon } from "lucide-react"; import { NpcDirectory } from "@/components/frontend/personnel/NpcDirectory"; +import { loadUnreadNpcIds } from "@/lib/npc-dialogue/unread"; +import { canSeeTestingDialogues } from "@/lib/npc-dialogue/visibility"; import { ClassificationStrip, CornerBrackets, DOSSIER } from "@/components/frontend/operations"; export const metadata = { @@ -24,6 +26,18 @@ export default async function ContactsPage() { }); const npcs = npcsRes.docs as unknown as GameNpc[]; + // Which contacts have conversation content this player has never opened. Two + // queries for the whole page, not one per card, and the same gates the offer + // uses: `canMessage` first, because a contact that cannot start a + // conversation should not advertise one, then the entry gate and testing + // flag inside the loader. + const canSeeTesting = await canSeeTestingDialogues(payload, user); + const unreadNpcIds = await loadUnreadNpcIds(payload, { + npcIds: npcs.filter((npc) => npc.canMessage === true).map((npc) => npc.id), + userId: user?.id ?? null, + canSeeTesting, + }).catch(() => []); + return (
@@ -49,7 +63,7 @@ export default async function ContactsPage() {
- + ); } diff --git a/src/components/frontend/personnel/NpcCard.tsx b/src/components/frontend/personnel/NpcCard.tsx index ce8d23a6..77cca4b8 100644 --- a/src/components/frontend/personnel/NpcCard.tsx +++ b/src/components/frontend/personnel/NpcCard.tsx @@ -9,9 +9,11 @@ import { initialsOf } from "@/components/frontend/personnel/initials"; interface NpcCardProps { readonly npc: GameNpc; + /** This contact offers conversation content the player has never read. */ + readonly unread?: boolean; } -export function NpcCard({ npc }: NpcCardProps) { +export function NpcCard({ npc, unread = false }: NpcCardProps) { const factionName = typeof npc.faction === "object" && npc.faction !== null ? npc.faction.name : null; const locationName = @@ -33,7 +35,7 @@ export function NpcCard({ npc }: NpcCardProps) { return (
@@ -41,6 +43,18 @@ export function NpcCard({ npc }: NpcCardProps) { + {/* New conversation content. Positioned over the portrait rather than in + the readout footer, which is already three cells wide. */} + {unread && ( +