mirror of
https://github.com/block/buzz.git
synced 2026-11-01 06:51:17 +00:00
Signed-off-by: Will Pfleger <pfleger.will@gmail.com> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import type { ConfigNudgePayload } from "@/shared/lib/configNudge";
|
|
import { extractConfigNudge } from "@/shared/lib/configNudge";
|
|
import { normalizePubkey } from "@/shared/lib/pubkey";
|
|
|
|
/**
|
|
* Pure helper that computes the active `ConfigNudgePayload` for a message body.
|
|
*
|
|
* Called by `MarkdownInner` inside a `useMemo`; when the return value is
|
|
* non-null the markdown prose node is suppressed (via `selectProseOrNudge`)
|
|
* and replaced by `ConfigNudgeCard`.
|
|
*
|
|
* Extracted into its own module so it can be imported and tested without
|
|
* pulling in `markdown.tsx`'s heavy dependency chain (Tauri, emoji-mart, etc.).
|
|
*/
|
|
export function computeConfigNudge(
|
|
content: string,
|
|
interactive: boolean,
|
|
configNudgeAuthorPubkey: string | undefined | null,
|
|
): ConfigNudgePayload | null {
|
|
if (!interactive || !configNudgeAuthorPubkey) return null;
|
|
const payload = extractConfigNudge(content);
|
|
if (payload === null) return null;
|
|
if (
|
|
normalizePubkey(payload.agent_pubkey) !==
|
|
normalizePubkey(configNudgeAuthorPubkey)
|
|
) {
|
|
return null;
|
|
}
|
|
return payload;
|
|
}
|
|
|
|
/**
|
|
* Returns `markdownNode` when no trusted config-nudge payload is present,
|
|
* or `null` when the card should render instead.
|
|
*
|
|
* This is the single production copy of the prose-suppression branch.
|
|
* `MarkdownInner` calls this instead of an inline ternary so the test suite
|
|
* can import and exercise the exact same branch, making a suppression revert
|
|
* observable at unit-test time.
|
|
*/
|
|
export function selectProseOrNudge(
|
|
configNudge: ConfigNudgePayload | null,
|
|
markdownNode: ReactNode,
|
|
): ReactNode {
|
|
return configNudge === null ? markdownNode : null;
|
|
}
|