mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
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 | | --- | --- | |  |  | buzz-review-completed Signed-off-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
157 lines
5.0 KiB
Dart
157 lines
5.0 KiB
Dart
part of '../message_content.dart';
|
|
|
|
/// A [maxLines] preview of a message for list rows such as the inbox and
|
|
/// search results.
|
|
///
|
|
/// The preview is one [Text.rich] built by [messagePreviewPieces], not
|
|
/// parsed Markdown: mentions, channels and custom emoji keep their chips,
|
|
/// links show their label and media shows its kind. Opening the row shows the
|
|
/// message in full.
|
|
class MessagePreview extends HookConsumerWidget {
|
|
final String content;
|
|
final Map<String, String> mentionNames;
|
|
final Map<String, String> mentionLabels;
|
|
final Set<String> agentMentionPubkeys;
|
|
final List<List<String>> tags;
|
|
final int maxLines;
|
|
final TextStyle? baseStyle;
|
|
final TextAlign? textAlign;
|
|
|
|
const MessagePreview({
|
|
super.key,
|
|
required this.content,
|
|
this.mentionNames = const {},
|
|
this.mentionLabels = const {},
|
|
this.agentMentionPubkeys = const {},
|
|
this.tags = const [],
|
|
this.maxLines = 2,
|
|
this.baseStyle,
|
|
this.textAlign,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final style =
|
|
baseStyle ??
|
|
context.textTheme.bodyMedium?.copyWith(color: context.colors.onSurface);
|
|
final channelNames = ref.watch(channelIdsByNameProvider);
|
|
final palette = ref.watch(customEmojiListProvider);
|
|
final pieces = useMemoized(
|
|
() {
|
|
final source = messagePreviewSource(content, maxLines: maxLines);
|
|
return messagePreviewPieces(
|
|
normalizeBareLinks(source),
|
|
maxLines: maxLines,
|
|
mentionBindings: renderedMentionBindings(
|
|
source,
|
|
mentionNames,
|
|
mentionedPubkeysFromTags(tags),
|
|
),
|
|
mentionNames: mentionNames,
|
|
mentionLabels: mentionLabels,
|
|
customEmoji: _referencedCustomEmoji(
|
|
source,
|
|
_mergeCustomEmoji(customEmojiFromTags(tags), palette),
|
|
),
|
|
channelNames: channelNames,
|
|
imetaByUrl: {
|
|
for (final entry in parseImetaTags(tags).entries)
|
|
normalizeMarkdownDestination(entry.key): entry.value,
|
|
},
|
|
);
|
|
},
|
|
[
|
|
content,
|
|
tags,
|
|
maxLines,
|
|
mentionNames,
|
|
mentionLabels,
|
|
channelNames,
|
|
palette,
|
|
],
|
|
);
|
|
if (pieces.isEmpty) return const SizedBox.shrink();
|
|
|
|
final agents = {for (final key in agentMentionPubkeys) key.toLowerCase()};
|
|
final mutedStyle = style?.copyWith(color: context.colors.onSurfaceVariant);
|
|
return Text.rich(
|
|
TextSpan(
|
|
style: style,
|
|
children: [
|
|
for (final piece in pieces)
|
|
switch (piece) {
|
|
PreviewText(:final text) => TextSpan(text: text),
|
|
PreviewMention(
|
|
:final pubkey,
|
|
:final label,
|
|
:final semanticsLabel,
|
|
) =>
|
|
WidgetSpan(
|
|
alignment: PlaceholderAlignment.baseline,
|
|
baseline: TextBaseline.alphabetic,
|
|
child: MessageMentionPill(
|
|
label: label,
|
|
pubkey: pubkey,
|
|
semanticsLabel: semanticsLabel,
|
|
isAgent: agents.contains(pubkey),
|
|
textStyle: style,
|
|
),
|
|
),
|
|
PreviewEmoji(:final shortcode, :final url) => WidgetSpan(
|
|
alignment: PlaceholderAlignment.middle,
|
|
child: CustomEmojiImage(
|
|
shortcode: shortcode,
|
|
url: url,
|
|
size: kCustomEmojiInlineSize,
|
|
),
|
|
),
|
|
PreviewChannel(:final name) => WidgetSpan(
|
|
alignment: PlaceholderAlignment.baseline,
|
|
baseline: TextBaseline.alphabetic,
|
|
child: _TokenPill(
|
|
icon: BuzzIcons.hash,
|
|
semanticLabel: 'Channel $name',
|
|
text: name,
|
|
textStyle: style?.copyWith(fontWeight: FontWeight.w500),
|
|
),
|
|
),
|
|
PreviewMedia(:final kind) => TextSpan(
|
|
text: switch (kind) {
|
|
MessageMediaKind.image => 'Image',
|
|
MessageMediaKind.video => 'Video',
|
|
MessageMediaKind.audio => 'Audio',
|
|
},
|
|
style: mutedStyle,
|
|
),
|
|
},
|
|
],
|
|
),
|
|
textAlign: textAlign,
|
|
maxLines: maxLines,
|
|
overflow: TextOverflow.ellipsis,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The palette entries [content] names, so a large community palette does
|
|
/// not cost every row.
|
|
Map<String, String> _referencedCustomEmoji(
|
|
String content,
|
|
List<CustomEmoji> palette,
|
|
) {
|
|
final referenced = {
|
|
for (final match in _previewShortcodeScan.allMatches(content))
|
|
match.group(1)!.toLowerCase(),
|
|
};
|
|
if (referenced.isEmpty) return const {};
|
|
return {
|
|
for (final emoji in palette)
|
|
if (referenced.contains(emoji.shortcode)) emoji.shortcode: emoji.url,
|
|
};
|
|
}
|
|
|
|
final _previewShortcodeScan = RegExp(
|
|
r'(?=:([a-z0-9_-]+):)',
|
|
caseSensitive: false,
|
|
);
|