From 1ac0b1dad107779f948bedf0483c590ab3a8d52b Mon Sep 17 00:00:00 2001 From: klopez4212 Date: Thu, 19 Nov 2026 18:31:32 +0000 Subject: [PATCH] Match mobile mention chips to desktop styling (#9706) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mobile mentions now use the desktop chip treatment: neutral rounded pills for other identities, the chat accent for mentions of the viewer, and a contrasting inset fill inside outgoing messages. This applies to message bodies and compact previews, while preserving profile taps and resolving self-highlights by public key. The change reuses the existing chat palette and keeps it stable across parent rebuilds, so unchanged messages retain their parsed Markdown. Mention routing and composer behavior are unchanged. Validation: `just mobile-check mobile-test` passed (5,118 Flutter tests, 71 skipped, plus 27 crypto-package tests). Coverage includes light/dark themes, 2× text, profile taps, live identity switching, outgoing contrast, and Markdown reuse; removing self-highlighting makes the regression fail. A signed iOS build was installed and checked on a physical device, then approved for PR preparation. ### Snapshots Actual Flutter component renders with synthetic identities and the bundled app font. Each shows received/own messages, compact previews, and enlarged text. | Light | Dark | | --- | --- | | ![Light mention chips](https://github.com/user-attachments/assets/54cd45ae-0196-4244-837c-2858e1768f11) | ![Dark mention chips](https://github.com/user-attachments/assets/b72be61f-c919-4a9d-8941-9d417e1309ba) | buzz-review-completed Signed-off-by: kenny lopez Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> --- .../features/channels/message_content.dart | 15 ++- .../message_content/inline_components.dart | 4 +- .../message_content/mention_markdown.dart | 4 + .../message_content/message_preview.dart | 1 + .../channels/message_mention_pill.dart | 75 +++++++++----- .../mention_chip_presentation_test.dart | 97 +++++++++++++++++++ 6 files changed, 172 insertions(+), 24 deletions(-) create mode 100644 mobile/test/features/channels/mention_chip_presentation_test.dart diff --git a/mobile/lib/features/channels/message_content.dart b/mobile/lib/features/channels/message_content.dart index ac5a29d2aa..e60c495976 100644 --- a/mobile/lib/features/channels/message_content.dart +++ b/mobile/lib/features/channels/message_content.dart @@ -1,8 +1,10 @@ import 'message_reply_drag_target.dart'; + import 'package:buzz/shared/widgets/feedback_snackbar.dart'; import 'dart:async'; import 'dart:convert'; + import '../../shared/widgets/ios_media_carousel.dart'; import '../../shared/widgets/message_attachment_corners.dart'; @@ -232,7 +234,13 @@ class MessageContent extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final markdownTheme = GptMarkdownTheme.of(context); - final chatColors = ChatColors.of(context); + final resolvedChatColors = ChatColors.of(context); + // The fallback palette is newly allocated; keep the nested theme stable so + // unchanged messages do not reparse their Markdown on parent rebuilds. + final chatColors = useMemoized(() => resolvedChatColors, [ + resolvedChatColors.outgoing, + resolvedChatColors.foreground, + ]); final ownTextColor = chatColors.foreground; // Own-bubble links share the bubble ink; markdown marks them by underline. final linkColor = ownMessage ? ownTextColor : context.colors.tertiary; @@ -396,6 +404,7 @@ class MessageContent extends HookConsumerWidget { }, [markdownContent, mentionPresentationKey]); final inlinePatterns = _useMessageInlinePatterns( + ownBubble: bubble && ownMessage, content: content, finalContent: finalContent, mentionNames: resolvedMentionNames, @@ -554,6 +563,10 @@ class MessageContent extends HookConsumerWidget { ), child: Theme( data: Theme.of(context).copyWith( + extensions: [ + ...Theme.of(context).extensions.values, + chatColors, + ], colorScheme: context.colors.copyWith( primary: linkColor, ), diff --git a/mobile/lib/features/channels/message_content/inline_components.dart b/mobile/lib/features/channels/message_content/inline_components.dart index 50f015fd3b..5ebd555c85 100644 --- a/mobile/lib/features/channels/message_content/inline_components.dart +++ b/mobile/lib/features/channels/message_content/inline_components.dart @@ -1,6 +1,7 @@ part of '../message_content.dart'; List _useMessageInlinePatterns({ + required bool ownBubble, required String content, required String finalContent, required Map mentionNames, @@ -51,6 +52,7 @@ List _useMessageInlinePatterns({ return useMemoized( () => [ _MentionMd( + ownBubble: ownBubble, mentionNames: inputs.mentionNames, mentionLabels: inputs.mentionLabels, bindings: inputs.bindings, @@ -71,7 +73,7 @@ List _useMessageInlinePatterns({ onChannelTap: channelTap, ).pattern, ], - [inputs], + [inputs, ownBubble], ); } diff --git a/mobile/lib/features/channels/message_content/mention_markdown.dart b/mobile/lib/features/channels/message_content/mention_markdown.dart index c20a12c5c8..fbbe400ee7 100644 --- a/mobile/lib/features/channels/message_content/mention_markdown.dart +++ b/mobile/lib/features/channels/message_content/mention_markdown.dart @@ -1,6 +1,7 @@ part of '../message_content.dart'; class _MentionMd { + final bool ownBubble; final Map> bindings; final Map displayLabels; final Map mentionNames; @@ -15,6 +16,7 @@ class _MentionMd { _MentionMd({ required this.bindings, + required this.ownBubble, required this.displayLabels, required this.mentionNames, required this.mentionLabels, @@ -58,6 +60,8 @@ class _MentionMd { ); final pill = MessageMentionPill( label: visibleLabel, + pubkey: pubkey, + ownBubble: ownBubble, semanticsLabel: fullLabel, isAgent: isAgent, textStyle: style, diff --git a/mobile/lib/features/channels/message_content/message_preview.dart b/mobile/lib/features/channels/message_content/message_preview.dart index 746d6f8b7d..210f96b97c 100644 --- a/mobile/lib/features/channels/message_content/message_preview.dart +++ b/mobile/lib/features/channels/message_content/message_preview.dart @@ -91,6 +91,7 @@ class MessagePreview extends HookConsumerWidget { baseline: TextBaseline.alphabetic, child: MessageMentionPill( label: label, + pubkey: pubkey, semanticsLabel: semanticsLabel, isAgent: agents.contains(pubkey), textStyle: style, diff --git a/mobile/lib/features/channels/message_mention_pill.dart b/mobile/lib/features/channels/message_mention_pill.dart index 4d825a7452..4989737a3a 100644 --- a/mobile/lib/features/channels/message_mention_pill.dart +++ b/mobile/lib/features/channels/message_mention_pill.dart @@ -1,10 +1,13 @@ import 'package:flutter/material.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; + +import '../../shared/relay/relay_provider.dart'; import '../../shared/widgets/buzz_agent_icon.dart'; import '../../shared/theme/theme.dart'; /// The inline identity label shared by chat mentions and channel actions. -class MessageMentionPill extends StatelessWidget { +class MessageMentionPill extends ConsumerWidget { /// Visible contextual identity name. final String label; @@ -14,6 +17,12 @@ class MessageMentionPill extends StatelessWidget { /// Whether to use the desktop robot icon instead of the @ prefix. final bool isAgent; + /// Resolved identity; unresolved names never receive the self highlight. + final String? pubkey; + + /// Whether the chip sits inside the viewer’s colored message bubble. + final bool ownBubble; + /// Typography inherited from the surrounding message. final TextStyle? textStyle; @@ -24,38 +33,60 @@ class MessageMentionPill extends StatelessWidget { this.semanticsLabel, required this.isAgent, this.textStyle, + this.pubkey, + this.ownBubble = false, }); @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { + final viewer = pubkey == null ? null : ref.watch(myPubkeyProvider); + final isSelf = + viewer != null && pubkey?.toLowerCase() == viewer.toLowerCase(); + final chat = ChatColors.of(context); + final ink = ownBubble || isSelf + ? chat.foreground + : context.colors.onSurface; + final fill = ownBubble + ? chatCodeTint(chat.foreground, 0.18) + : isSelf + ? chat.outgoing + : (context.colors.brightness == Brightness.dark + ? Colors.white.withValues(alpha: 0.16) + : Colors.black.withValues(alpha: 0.10)); final style = (textStyle ?? context.textTheme.bodyMedium)?.copyWith( - color: context.colors.primary, + color: ink, fontWeight: FontWeight.w500, height: 1, ) ?? - TextStyle( - color: context.colors.primary, - fontWeight: FontWeight.w500, - height: 1, - ); + TextStyle(color: ink, fontWeight: FontWeight.w500, height: 1); final fontSize = style.fontSize ?? 16; - return Row( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - if (isAgent) - BuzzAgentIcon(size: fontSize, color: context.colors.primary) - else - Transform.translate( - offset: const Offset(0, -Grid.quarter), - child: Text('@', style: style), + return Container( + padding: const EdgeInsets.symmetric( + horizontal: Grid.quarter * 1.5, + vertical: Grid.quarter, + ), + decoration: BoxDecoration( + color: fill, + borderRadius: BorderRadius.circular(Radii.full), + ), + child: Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + if (isAgent) + BuzzAgentIcon(size: fontSize, color: ink) + else + Transform.translate( + offset: const Offset(0, -Grid.quarter), + child: Text('@', style: style), + ), + Flexible( + child: Text(label, style: style, semanticsLabel: semanticsLabel), ), - Flexible( - child: Text(label, style: style, semanticsLabel: semanticsLabel), - ), - ], + ], + ), ); } } diff --git a/mobile/test/features/channels/mention_chip_presentation_test.dart b/mobile/test/features/channels/mention_chip_presentation_test.dart new file mode 100644 index 0000000000..a9e62d4fed --- /dev/null +++ b/mobile/test/features/channels/mention_chip_presentation_test.dart @@ -0,0 +1,97 @@ +import 'package:buzz/features/channels/message_content.dart'; +import 'package:buzz/features/channels/message_mention_pill.dart'; +import 'package:buzz/shared/relay/relay.dart'; +import 'package:buzz/shared/theme/theme.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; + +void main() { + testWidgets( + 'mentions follow identity, bubble, and appearance while staying tappable', + (tester) async { + final container = ProviderContainer( + overrides: [myPubkeyProvider.overrideWithValue('alice')], + ); + addTearDown(container.dispose); + String? tapped; + const names = {'alice': 'Alice', 'bob': 'Bob'}; + for (final brightness in Brightness.values) { + for (final own in [false, true]) { + final theme = mobileAppearanceTheme(brightness, '#c0a2f1'); + final chat = theme.extension()!; + await tester.pumpWidget( + UncontrolledProviderScope( + container: container, + child: MaterialApp( + theme: theme, + home: Scaffold( + body: MediaQuery( + data: const MediaQueryData( + size: Size(800, 600), + textScaler: TextScaler.linear(2), + ), + child: AppMarkdownTheme( + child: SizedBox( + width: 320, + child: MessageContent( + content: 'Hello @Alice and @Bob', + mentionNames: names, + bubble: true, + ownMessage: own, + onMentionTap: (key) => tapped = key, + ), + ), + ), + ), + ), + ), + ), + ); + await tester.pumpAndSettle(); + Color fill(String label) { + final pill = find.ancestor( + of: find.text(label), + matching: find.byType(MessageMentionPill), + ); + final box = tester.widget( + find.descendant(of: pill, matching: find.byType(Container)).first, + ); + return (box.decoration! as BoxDecoration).color!; + } + + expect( + fill('Alice'), + own ? chatCodeTint(chat.foreground, .18) : chat.outgoing, + ); + expect( + fill('Bob'), + own + ? chatCodeTint(chat.foreground, .18) + : (brightness == Brightness.dark + ? Colors.white.withValues(alpha: .16) + : Colors.black.withValues(alpha: .10)), + ); + tapped = null; + await tester.tap(find.text('Bob')); + expect(tapped, 'bob'); + expect(tester.takeException(), isNull); + + // Switching identity updates already-parsed spans, without new content. + container.updateOverrides([ + myPubkeyProvider.overrideWithValue('bob'), + ]); + await tester.pump(); + if (!own) { + expect(fill('Bob'), chat.outgoing); + expect(fill('Alice'), isNot(chat.outgoing)); + } + container.updateOverrides([ + myPubkeyProvider.overrideWithValue('alice'), + ]); + await tester.pump(); + } + } + }, + ); +}