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:
Matt Toohey
2026-11-17 18:37:47 +11:00
parent c4d3f2072b
commit 4e4ac3efd8
7 changed files with 1087 additions and 61 deletions

View File

@@ -7,6 +7,7 @@ import '../../../shared/identity_names/identity_names.dart';
import '../../../shared/identity_names/identity_names_provider.dart';
import '../../../shared/mentions/agent_identity_provider.dart';
import '../../../shared/relay/relay.dart';
import '../../../shared/utils/string_utils.dart';
import '../../../shared/profile/user_cache_provider.dart';
import '../../../shared/profile/user_profile.dart';
import '../../../shared/verified_profiles/verified_profile.dart';
@@ -103,13 +104,16 @@ class MentionSearchCache {
/// The last finished search that found nobody, or null.
String? _refuted;
/// Lowercase only, not the section 3 folding: the directory is the relay's
/// search, whose prefix rule is what a refutation reasons about, so an
/// accented query is a different search, not a continuation of the plain
/// one. The device still matches members and found people by folding.
static String _key(String query) => query.trim().toLowerCase();
/// Only a query with a letter or digit searches names; a public key is an
/// author lookup that no name prefix can refute.
/// Only a query with a letter or digit searches names; an exact public key
/// is an author lookup that no name prefix can refute.
static final _wordCharacter = RegExp(r'[\p{L}\p{N}]', unicode: true);
static final _npub = RegExp(r'^(?:nostr:)?npub1[02-9ac-hj-np-z]{58}$');
static bool _exactKey(String key) => isMentionKey(key) || _npub.hasMatch(key);
static bool _exactKey(String key) => typedPublicKey(key) != null;
/// Whether the last finished search found nobody for a shorter query that
/// [query] continues, so a search for [query] would find nobody either.