refactor: keep Buzz mention helpers internal

This commit is contained in:
Shakker
2026-08-02 06:38:35 +01:00
parent d4490c6a9d
commit 3de2a752f5
2 changed files with 10 additions and 14 deletions
+6 -3
View File
@@ -1,7 +1,7 @@
import { nip19 } from "nostr-tools";
import { describe, expect, it } from "vitest";
import {
hasBuzzMentionSyntax,
inspectBuzzMentionSyntax,
resolveBuzzMessageMentions,
type BuzzMentionMember,
} from "./mentions.js";
@@ -27,7 +27,7 @@ describe("Buzz outbound mentions", () => {
});
it("resolves a known non-ASCII room-member name without treating emails as mentions", () => {
expect(hasBuzzMentionSyntax("Hello @Élodie")).toBe(true);
expect(inspectBuzzMentionSyntax("Hello @Élodie").hasAtMention).toBe(true);
expect(
resolveBuzzMessageMentions({
text: "Hello @Élodie",
@@ -35,7 +35,10 @@ describe("Buzz outbound mentions", () => {
senderPublicKey: BOT_PUBLIC_KEY,
}),
).toEqual([ALICE_PUBLIC_KEY]);
expect(hasBuzzMentionSyntax("mail user@example.com")).toBe(false);
expect(inspectBuzzMentionSyntax("mail user@example.com")).toEqual({
hasAtMention: false,
hasExplicitIdentity: false,
});
});
it("rejects unknown non-ASCII mention text instead of publishing it without a tag", () => {
+4 -11
View File
@@ -8,11 +8,6 @@ export type BuzzMentionMember = {
displayName?: string;
};
export type BuzzMentionSyntax = {
hasAtMention: boolean;
hasExplicitIdentity: boolean;
};
const HEX_PUBLIC_KEY_PATTERN = /^[0-9a-f]{64}$/u;
const NIP_27_PREFIX = "nostr:npub1";
const NPUB_LENGTH = 63;
@@ -182,12 +177,10 @@ function normalizeMembers(members: readonly BuzzMentionMember[]): Map<string, Bu
return normalized;
}
export function hasBuzzMentionSyntax(text: string): boolean {
const syntax = inspectBuzzMentionSyntax(text);
return syntax.hasAtMention || syntax.hasExplicitIdentity;
}
export function inspectBuzzMentionSyntax(text: string): BuzzMentionSyntax {
export function inspectBuzzMentionSyntax(text: string): {
hasAtMention: boolean;
hasExplicitIdentity: boolean;
} {
const stripped = stripCodeRegions(text);
return {
hasAtMention: hasAtMentionCandidate(stripped),