mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
refactor: keep Buzz mention helpers internal
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user