Merge upstream/dev (10 commits) [upstream-sync]

This commit is contained in:
upstream-sync-bot committed 2026-11-16 04:52:13 +00:00
commit 5a53e45e9a
68 files changed
+6375 -178

No files matched your search

+142 -28
View File
@@ -31,6 +31,7 @@ import '../helpers/snack_bar_builder.dart';
import '../l10n/l10n.dart';
import '../models/channel.dart';
import '../models/channel_message.dart';
import '../models/bookmarked_message.dart';
import '../models/image_codec_support.dart' show aeicRatePointForUi;
import '../models/message_filter.dart';
import '../services/app_settings_service.dart' show AppSettingsService;
@@ -167,6 +168,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
/// Message ids picked for a bulk action. Non-empty means selection mode:
/// taps toggle messages and the app bar shows the bulk actions.
final Set<String> _selectedIds = <String>{};
bool _showBookmarkedOnly = false;
bool get _selecting => _selectedIds.isNotEmpty;
@override
@@ -576,6 +578,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
widget.channel,
onSaved: _onChannelEdited,
);
case 'showBookmarks':
setState(() {
_showBookmarkedOnly = !_showBookmarkedOnly;
_selectedIds.clear();
});
case 'background':
showChatBackgroundSheet(
context,
@@ -631,6 +638,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
enabled: !readOnly,
child: _menuRow(Icons.settings, context.l10n.channels_editChannel),
),
PopupMenuItem(
value: 'showBookmarks',
child: _menuRow(
_showBookmarkedOnly ? Icons.bookmark : Icons.bookmark_border,
context.l10n.chat_showBookmarks,
color: _showBookmarkedOnly ? const Color(0xFFFFE54A) : null,
),
),
PopupMenuItem(
value: 'background',
child: _menuRow(Icons.wallpaper, context.l10n.chatBackground_title),
@@ -858,13 +873,22 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
final layout = _transcriptLayoutFor(
context,
messages,
showBookmarkedOnly: _showBookmarkedOnly,
);
// Fewer entries than messages means the filter hid or
// collapsed some; make sure older history stays reachable.
final hidesMessages = layout.length < messages.length;
// Fewer entries than messages means the message filter
// hid or collapsed some; bookmark filtering is deliberate.
final hidesMessages =
!_showBookmarkedOnly &&
layout.length < messages.length;
if (hidesMessages) _scheduleHiddenHistoryBackfill();
if (layout.length == 0) {
if (_showBookmarkedOnly) {
return EmptyState(
icon: Icons.bookmark_border,
title: context.l10n.bookmarks_empty,
);
}
final canLoadOlder =
hidesMessages && !_olderHistoryExhausted;
return EmptyState(
@@ -1195,6 +1219,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
: null,
child: MessageBubbleFrame(
isOutgoing: isOutgoing,
isBookmarked: message.isBookmarked || _showBookmarkedOnly,
compact: gifId != null,
maxWidth: constraints.maxWidth,
child: Column(
@@ -1924,9 +1949,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
final connector = context.read<MeshCoreConnector>();
// The picked bytes are kept past the preview on purpose: the sender's own
// bubble renders from them (see [_registerOutgoingImage]). The bitstream
// cannot serve — turning it back into pixels is a ~2.16 GiB, ~1 s decode
// of an image the sender is already holding.
// bubble falls back to them (see [_registerOutgoingImage]) when the sheet
// could not decode the chosen version on this device.
final XFile? picked;
try {
picked = await ImagePicker().pickImage(
@@ -2102,8 +2126,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
/// GRP_DATA is not echoed back to the sender and an image is not a
/// [ChannelMessage], so without this the sender sees a "sent" snack bar and
/// an otherwise empty conversation. The entry lands in `decoded` directly —
/// an outgoing image is never queued for inference, so showing your own
/// photo costs no model memory.
/// an outgoing image is never queued for inference.
///
/// The bubble shows the version the user picked, decoded as recipients see
/// it ([ImageSendPreviewResult.previewPng]). Only when this device could not decode does it fall back
/// to the stretched original.
///
/// Best effort throughout: a failure here has already been preceded by a
/// successful transmission, so it must not turn into an error the user sees.
@@ -2119,7 +2146,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
} on ProviderNotFoundException {
return; // screen test without the store
}
final previewPng = await _squarePreviewPng(sourceBytes);
final previewPng =
result.previewPng ?? await _squarePreviewPng(sourceBytes);
if (previewPng == null) return;
try {
await store.registerOutgoing(
@@ -2133,6 +2161,18 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
rate: aeicRatePointForUi(result.rate),
chunkCount: chunkSet.dataChunkCount,
aspectCode: await _aspectCodeOf(sourceBytes),
// The decoded version is model output and carries the AI label; the
// stretched-original fallback is the sender's own pixels.
synthesized: result.previewPng != null,
payloadBytes: result.payload.length,
// Repeaters may already have echoed the first chunks while the rest
// were still going out.
chunkEchoes: mounted
? context.read<MeshCoreConnector>().ownImageEchoes(
widget.channel.index,
chunkSet.imgId,
)
: null,
);
} on Exception catch (error) {
debugPrint('outgoing image registration failed: $error');
@@ -2160,11 +2200,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
/// [imageBytes] stretched to 512x512, as PNG.
///
/// This is what the preview sheet showed (`BoxFit.fill` on a 1:1 box is
/// exactly the stretch the codec applies) and what the codec actually
/// encoded, so the sender's bubble matches both. Deliberately not a decode of the
/// bitstream: that would cost ~2.16 GiB and ~1 s to reproduce, less well, an
/// image this device is already holding in memory.
/// Fallback for the sender's bubble when the preview sheet had no decoded
/// version to hand over (a device that cannot decode). It is the input the
/// codec stretched, not what recipients see, so it is only a stand-in.
///
/// Returns null rather than throwing on an undecodable source — the send has
/// already happened by the time this runs.
@@ -2219,8 +2257,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
/// `State`'s) — `watch` asserts on that.
_TranscriptLayout _transcriptLayoutFor(
BuildContext context,
List<ChannelMessage> messages,
) {
List<ChannelMessage> messages, {
bool showBookmarkedOnly = false,
}) {
ReceivedImageStore? store;
try {
store = context.watch<ReceivedImageStore>();
@@ -2249,10 +2288,17 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
displayMode,
filterActive,
_revealVersion,
showBookmarkedOnly,
_filteredMessagesSignature(messages),
Object.hashAll(
messages
.where((message) => message.isBookmarked)
.map((message) => message.messageId),
),
);
final cached = _transcriptLayout;
if (cached != null &&
if (!showBookmarkedOnly &&
cached != null &&
cached.matches(
messages,
_imageStoreVersion,
@@ -2261,11 +2307,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
)) {
return cached;
}
final images = store == null
final displayedMessages = showBookmarkedOnly
? messages.where((message) => message.isBookmarked).toList()
: messages;
final images = store == null || showBookmarkedOnly
? const <ReceivedImageEntry>[]
: store.entriesForChannel(widget.channel.storageId);
final layout = _TranscriptLayout.build(
messages: messages,
messages: displayedMessages,
images: images,
imageVersion: _imageStoreVersion,
channelIndex: widget.channel.index,
@@ -2407,12 +2456,35 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
right: 8,
bottom: 4,
),
child: Text(
formatChatTime(context, entry.firstSeen),
style: MeshTheme.mono(
fontSize: 12 * textScale,
color: metaColor,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
formatChatTime(context, entry.firstSeen),
style: MeshTheme.mono(
fontSize: 12 * textScale,
color: metaColor,
),
),
if (isOutgoing) ...[
const SizedBox(width: 4),
// Same status as channel text: repeats heard, here
// for the least-heard data chunk.
MessageStatusIcon(
size: 16 * textScale,
isAcked: false,
isChannel: true,
repeatCount: entry.minDataChunkEchoes ?? 0,
resendProgress: context
.watch<MeshCoreConnector>()
.imageResendProgress(
entry.channelIndex,
entry.imgId,
),
onColor: metaColor,
),
],
],
),
),
],
@@ -2545,6 +2617,15 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
if (entry.recoveredWithParity)
Text(l10n.receivedImage_parityRecovered),
if (decodeMs != null) Text(l10n.receivedImage_decodeTime(decodeMs)),
if (entry.chunkEchoes case final echoes?) ...[
const SizedBox(height: 8),
for (var i = 0; i < echoes.length; i++)
Text(
i < entry.totalChunks
? l10n.receivedImage_packetEchoes(i + 1, echoes[i])
: l10n.receivedImage_recoveryPacketEchoes(echoes[i]),
),
],
],
),
actions: [
@@ -3028,6 +3109,38 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
_markAsUnread(message);
},
),
ListTile(
leading: Icon(
message.isBookmarked
? Icons.bookmark_remove_outlined
: Icons.bookmark_add_outlined,
),
title: Text(
message.isBookmarked
? context.l10n.chat_removeBookmark
: context.l10n.chat_bookmark,
),
onTap: () {
Navigator.pop(sheetContext);
final bookmark = BookmarkedMessage.fromChannel(
message: message,
channelId:
widget.channel.storageId ??
'slot:${widget.channel.index}',
channelName: widget.channel.name,
senderName: message.isOutgoing
? (context.read<MeshCoreConnector>().selfName ??
context.l10n.chat_me)
: message.senderName,
);
unawaited(
context.read<MeshCoreConnector>().setBookmarkedMessage(
bookmark,
isBookmarked: !message.isBookmarked,
),
);
},
),
if (showFilterActions) ...[
const Divider(height: 1),
if (message.isFiltered)
@@ -3128,9 +3241,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
final filterActive = _transcriptLayout?.filterActive ?? true;
return [
for (final m in messages)
if (!(filterActive &&
m.isFiltered &&
!_revealedFilteredIds.contains(m.messageId)))
if ((!_showBookmarkedOnly || m.isBookmarked) &&
!(filterActive &&
m.isFiltered &&
!_revealedFilteredIds.contains(m.messageId)))
m,
];
}