buzz icon indicating copy to clipboard operation
buzz copied to clipboard

fix(mobile): show npub on same-named mention suggestions

Open AI-OWEN opened this issue 3 months ago • 0 comments

Problem

The desktop MentionAutocomplete counts display names in the suggestion list and, when two share a name, prints each candidate's truncated npub underneath so they can be told apart:

// Name collisions are the impersonation vector: a vanity-ground key can
// wear any display name. When two suggestions share a name, surface each
// one's npub (truncated; full key in the hover tooltip) to tell them apart.

The Flutter composer has no equivalent — grep -ri collision mobile/lib mobile/test returns nothing.

The result on mobile is that identities sharing a display name render identically: same name, same avatar, and the same managed by you · not in channel subtitle. There is nothing on screen to distinguish them.

This came out of real use. An owner whose agent had been re-registered several times ended up with five identities all called the same thing — one live, the rest dormant — and could not tell which row in the @ picker was the live one. Mentioning a dormant key is silent: nothing answers.

Worth being precise about scope: offering non-member agents is deliberate (buildMentionCandidates includes agents you own even outside the channel, mirroring desktop). The gap is only that the picker gives no way to tell them apart.

Change

  • mentionNameCollisions() in mention_ranking.dart returns the lowercase labels shared by more than one candidate. Extracted as a pure function rather than inlined in the widget (as desktop does) so the collision rule is unit-testable on its own.
  • The suggestion subtitle gains a monospace npub line, for colliding names only — uniquely-named suggestions are untouched.
  • safeNpub() / truncatePubkey() in string_utils.dart mirror their desktop counterparts. truncatePubkey keeps both ends (abcd1234…wxyz) rather than reusing the existing head-only shortPubkey: every npub begins with npub1, so a head-only form leaves barely three distinguishing characters.

A truncated key is a recognition aid, not identity proof. The line narrows the choice; it does not authenticate it.

Tests

  • 5 unit tests for mentionNameCollisions — unique labels, a shared label, case-insensitive matching, the pubkey-fallback label (which must not collide), and multiple distinct collisions.
  • 2 widget tests driving the real composer: two same-named agents each render their own distinct npub; a uniquely-named agent renders none.

The collision widget test was confirmed to fail with the suggestions.dart change reverted, so it is load-bearing rather than merely passing.

flutter analyze   No issues found!
dart format       355 files (0 changed)
flutter test      All tests passed!  (1169 tests)

Not in this PR

Desktop already has this behaviour, so no change there. Web has no mention autocomplete.

🤖 Generated with Claude Code

AI-OWEN avatar Aug 04 '26 09:08 AI-OWEN