mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
fix(mobile): fold accents when matching mention names
`@jos` listed José María, `@jose` listed nobody and `@josé` listed them again: mobile only lowercased names. Name matching now follows section 3 of the shared mention rules, as buzz-app does (recommendation 6). Each code point is NFKD-normalized, its combining accents (the Combining Diacritical Marks blocks) are removed, it is lowercased and a final `ς` becomes `σ`, so `jose` matches `José`, `fiona` matches `fio` and `jose` matches `jose`, while `ø`, `ł`, `æ`, `ß`, `ı` and the marks of other scripts stay distinct. Words are runs of letters, marks and digits, so a hyphen or apostrophe separates them: `jane` finds `Mary-Jane` and `brien` finds `O'Brien`. The folding lives in `name_match.dart` and drives the chooser, Space selection, multi-word admission, the verified-name matches and the recipient pickers, so `@jose maria` lists José María with no accents typed. The vendored fixture moves from version 1 (95 cases) to version 4 of buzz-app's `mention-rules.fixtures.json` (125 cases), copied unchanged, and the conformance test runs every section, with a new `matching` group. No case is skipped. The rules the newer versions added are implemented too: an exact public key (64 hex in either case, or a complete lowercase or uppercase npub with an optional `nostr:` prefix) matches only its owner, even one with no name, and Space selects that owner; the viewer's own agent whose name continues the query with a new word leads (`Sol 6` for `sol`), and an exact person leads over it; agents from the viewer's other communities follow everyone here; an outside choice's longer name no longer blocks a member's exact name on Space, and a choice's own longer alias is not its own namesake. The search cache's exact-key exemption uses the same `typedPublicKey`. Refutation itself stays lowercase-only on purpose: it reasons about the relay's prefix search, which is out of scope here, so an accented query is a new search rather than a continuation. A refuted query still matches members on the device by folding: after `z` finds nobody, `@zoe` lists the member Zoë without a search. Tests: the compose bar search journey types `@jose maria` and sees José María, and `@zoe` after the `z` refutation sees Zoë; both and seven fixture cases fail when accent stripping is removed. `dart format`, `flutter analyze` and the full mobile `flutter test` suite pass. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
This commit is contained in:
@@ -50,6 +50,34 @@ String? fullNpub(String identity) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The hex public key that typed text names exactly (portable mention rules,
|
||||
/// Terms): 64 hex characters in either case, or a complete all-lowercase or
|
||||
/// all-uppercase npub, with or without a `nostr:` prefix in any case. Null
|
||||
/// for anything else, including a key still being typed, a mixed-case npub,
|
||||
/// or one with a bad checksum or a payload of another length.
|
||||
String? typedPublicKey(String text) {
|
||||
final value = text.trim();
|
||||
if (isHexPubkey(value)) return value.toLowerCase();
|
||||
const scheme = 'nostr:';
|
||||
final npub =
|
||||
value.length > scheme.length &&
|
||||
value.substring(0, scheme.length).toLowerCase() == scheme
|
||||
? value.substring(scheme.length)
|
||||
: value;
|
||||
if (!npub.toLowerCase().startsWith('npub1')) return null;
|
||||
try {
|
||||
// bech32 rejects mixed case itself.
|
||||
final decoded = nostr.Nip19.decode(payload: npub);
|
||||
if (decoded.prefix != nostr.Nip19Prefix.npub ||
|
||||
!isHexPubkey(decoded.data)) {
|
||||
return null;
|
||||
}
|
||||
return decoded.data.toLowerCase();
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Encoded npubs by lowercase hex key. Identity views label every roster
|
||||
/// member without a profile name by npub on each rebuild, and bech32 encoding
|
||||
/// dominated those rebuilds on large channels. Bounded: once full it keeps
|
||||
|
||||
Reference in New Issue
Block a user