Merge upstream/dev (10 commits) [upstream-sync]
This commit is contained in:
commit
5a53e45e9a
68 files changed
+6375
-178
No files matched your search
@@ -16,6 +16,7 @@ import '../services/app_settings_service.dart';
|
||||
import '../services/backup_service.dart';
|
||||
import '../services/image_codec_service.dart';
|
||||
import '../services/translation_service.dart';
|
||||
import '../services/ui_view_state_service.dart';
|
||||
import '../services/message_filter/message_filter_service.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
import '../utils/share_origin.dart';
|
||||
@@ -201,6 +202,11 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
l10n.backupRestore_discoveredContacts,
|
||||
Icons.person_search_outlined,
|
||||
),
|
||||
_itemTile(
|
||||
BackupItem.bookmarks,
|
||||
l10n.backupRestore_bookmarks,
|
||||
Icons.bookmark_border,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
_groupTile(
|
||||
title: l10n.backupRestore_channels,
|
||||
@@ -432,6 +438,7 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final appSettingsService = context.read<AppSettingsService>();
|
||||
final uiViewStateService = context.read<UiViewStateService>();
|
||||
final messageFilterService = context.read<MessageFilterService>();
|
||||
final translationService = context.read<TranslationService>();
|
||||
final imageCodecService = context.read<ImageCodecService>();
|
||||
@@ -454,6 +461,7 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
|
||||
)) {
|
||||
await appSettingsService.loadSettings();
|
||||
if (_selectedItems.contains(BackupItem.appSettings)) {
|
||||
await uiViewStateService.reload();
|
||||
await _offerMissingModels(
|
||||
appSettingsService,
|
||||
translationService,
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/message_url_image_helper.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/bookmarked_message.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../widgets/chat_send_pipeline.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/translated_message_content.dart';
|
||||
|
||||
class BookmarksScreen extends StatefulWidget {
|
||||
const BookmarksScreen({super.key});
|
||||
|
||||
@override
|
||||
State<BookmarksScreen> createState() => _BookmarksScreenState();
|
||||
}
|
||||
|
||||
class _BookmarksScreenState extends State<BookmarksScreen> {
|
||||
late Future<List<BookmarkedMessage>> _bookmarks;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_bookmarks = context.read<MeshCoreConnector>().loadBookmarkedMessages();
|
||||
}
|
||||
|
||||
void _reload() {
|
||||
setState(() {
|
||||
_bookmarks = context.read<MeshCoreConnector>().loadBookmarkedMessages();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _remove(BookmarkedMessage bookmark) async {
|
||||
await context.read<MeshCoreConnector>().setBookmarkedMessage(
|
||||
bookmark,
|
||||
isBookmarked: false,
|
||||
);
|
||||
if (mounted) _reload();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final publicIpfsGateway = context
|
||||
.watch<AppSettingsService>()
|
||||
.settings
|
||||
.publicIpfsGateway;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(l10n.bookmarks_title), centerTitle: true),
|
||||
body: FutureBuilder<List<BookmarkedMessage>>(
|
||||
future: _bookmarks,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final bookmarks = snapshot.data ?? const <BookmarkedMessage>[];
|
||||
if (bookmarks.isEmpty) {
|
||||
return EmptyState(
|
||||
icon: Icons.bookmark_border,
|
||||
title: l10n.bookmarks_empty,
|
||||
);
|
||||
}
|
||||
bookmarks.sort((a, b) => a.receivedAt.compareTo(b.receivedAt));
|
||||
return ListView.builder(
|
||||
reverse: true,
|
||||
padding: const EdgeInsets.all(12),
|
||||
itemCount: bookmarks.length,
|
||||
itemBuilder: (context, index) {
|
||||
final bookmark = bookmarks[bookmarks.length - 1 - index];
|
||||
final sourceType =
|
||||
bookmark.sourceType == BookmarkSourceType.channel
|
||||
? l10n.bookmarks_channel
|
||||
: l10n.bookmarks_contact;
|
||||
final receivedAt = bookmark.receivedAt.toLocal();
|
||||
final localizations = MaterialLocalizations.of(context);
|
||||
final time = localizations.formatTimeOfDay(
|
||||
TimeOfDay.fromDateTime(receivedAt),
|
||||
alwaysUse24HourFormat: MediaQuery.alwaysUse24HourFormatOf(
|
||||
context,
|
||||
),
|
||||
);
|
||||
final dateTime =
|
||||
'${localizations.formatShortDate(receivedAt)} $time';
|
||||
final translation = bookmark.translatedText?.trim();
|
||||
final displayText = translation?.isNotEmpty == true
|
||||
? translation!
|
||||
: bookmark.text;
|
||||
final textStyle =
|
||||
Theme.of(context).textTheme.bodyMedium ?? const TextStyle();
|
||||
final textContent = TranslatedMessageContent(
|
||||
displayText: displayText,
|
||||
originalText: displayText == bookmark.text
|
||||
? null
|
||||
: bookmark.text,
|
||||
style: textStyle,
|
||||
originalStyle: textStyle.copyWith(fontStyle: FontStyle.italic),
|
||||
);
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 8, 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: 2, right: 8),
|
||||
child: Icon(
|
||||
Icons.bookmark,
|
||||
size: 20,
|
||||
color: Color(0xFFFFE54A),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'$sourceType · ${bookmark.sourceName}',
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'${bookmark.senderName} · $dateTime',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.common_copy,
|
||||
onPressed: () =>
|
||||
copyChatMessageText(context, bookmark.text),
|
||||
icon: const Icon(Icons.copy),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: l10n.bookmarks_remove,
|
||||
onPressed: () => _remove(bookmark),
|
||||
icon: const Icon(Icons.bookmark_remove_outlined),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (MessageUrlImageHelper.hasPotentialImageUrl(
|
||||
bookmark.text,
|
||||
))
|
||||
MessageUrlImageFutureBuilder(
|
||||
messageId: bookmark.messageId,
|
||||
text: bookmark.text,
|
||||
publicGateway: publicIpfsGateway,
|
||||
builder: (context, snapshot) {
|
||||
final imageUrl = snapshot.data;
|
||||
if (imageUrl == null) return textContent;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: MessageUrlImagePreview(
|
||||
imageUrl: imageUrl,
|
||||
),
|
||||
),
|
||||
textContent,
|
||||
],
|
||||
);
|
||||
},
|
||||
)
|
||||
else
|
||||
textContent,
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import '../helpers/contact_share_message.dart';
|
||||
import '../helpers/gif_helper.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../helpers/utf8_length_limiter.dart';
|
||||
import 'bookmarks_screen.dart';
|
||||
import 'channel_chat_screen.dart';
|
||||
import 'community_qr_scanner_screen.dart';
|
||||
import 'contacts_screen.dart';
|
||||
@@ -128,6 +129,16 @@ class _ChannelsScreenState extends State<ChannelsScreen> {
|
||||
// context, which is deactivated by then.
|
||||
itemBuilder: (menuContext) => [
|
||||
connectionMenuItem(context, menuContext),
|
||||
PopupMenuItem(
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.bookmark_border,
|
||||
label: menuContext.l10n.bookmarks_title,
|
||||
),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const BookmarksScreen()),
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: MeshMenuItemRow(
|
||||
icon: Icons.groups,
|
||||
|
||||
@@ -28,6 +28,7 @@ import '../helpers/marker_message.dart';
|
||||
import '../helpers/message_search.dart';
|
||||
import '../widgets/chat_search_results.dart';
|
||||
import '../models/channel_message.dart';
|
||||
import '../models/bookmarked_message.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../l10n/contact_localization.dart';
|
||||
import '../models/message.dart';
|
||||
@@ -98,6 +99,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final _textFieldFocusNode = FocusNode();
|
||||
final GlobalKey _unreadScrollKey = GlobalKey();
|
||||
bool _isLoadingOlder = false;
|
||||
bool _showBookmarkedOnly = false;
|
||||
MeshCoreConnector? _connector;
|
||||
Message? _pendingUnreadScrollTarget;
|
||||
String? _unreadDividerMessageId;
|
||||
@@ -486,6 +488,10 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
_showContactInfo(context);
|
||||
case 'settings':
|
||||
_showContactSettings(context);
|
||||
case 'showBookmarks':
|
||||
setState(
|
||||
() => _showBookmarkedOnly = !_showBookmarkedOnly,
|
||||
);
|
||||
case 'background':
|
||||
showChatBackgroundSheet(
|
||||
context,
|
||||
@@ -553,6 +559,18 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
label: context.l10n.contact_settings,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'showBookmarks',
|
||||
child: MeshMenuItemRow(
|
||||
icon: _showBookmarkedOnly
|
||||
? Icons.bookmark
|
||||
: Icons.bookmark_border,
|
||||
label: context.l10n.chat_showBookmarks,
|
||||
color: _showBookmarkedOnly
|
||||
? const Color(0xFFFFE54A)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'background',
|
||||
child: MeshMenuItemRow(
|
||||
@@ -633,6 +651,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
if (_showBookmarkedOnly) return _buildBookmarkEmptyState();
|
||||
return EmptyState(
|
||||
icon: Icons.chat_bubble_outline,
|
||||
title: context.l10n.chat_noMessages,
|
||||
@@ -642,12 +661,23 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBookmarkEmptyState() => EmptyState(
|
||||
icon: Icons.bookmark_border,
|
||||
title: context.l10n.bookmarks_empty,
|
||||
);
|
||||
|
||||
Widget _buildMessageList(
|
||||
List<Message> messages,
|
||||
MeshCoreConnector connector,
|
||||
) {
|
||||
final visibleMessages = _showBookmarkedOnly
|
||||
? messages.where((message) => message.isBookmarked).toList()
|
||||
: messages;
|
||||
if (_showBookmarkedOnly && visibleMessages.isEmpty) {
|
||||
return _buildBookmarkEmptyState();
|
||||
}
|
||||
// Reverse messages so newest appear at bottom with reverse: true
|
||||
final reversedMessages = messages.reversed.toList();
|
||||
final reversedMessages = visibleMessages.reversed.toList();
|
||||
final itemCount = reversedMessages.length + (_isLoadingOlder ? 1 : 0);
|
||||
|
||||
// Auto-scroll to bottom if user is already at bottom
|
||||
@@ -717,6 +747,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
: contact.name,
|
||||
sourceId: widget.contact.publicKeyHex,
|
||||
textScale: textScale,
|
||||
isBookmarked: message.isBookmarked || _showBookmarkedOnly,
|
||||
onLongPress: () => _showMessageActions(message, contact),
|
||||
onRetryReaction: (msg, emoji) =>
|
||||
_sendReaction(msg, contact, emoji),
|
||||
@@ -1461,6 +1492,36 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
_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.fromContact(
|
||||
message: message,
|
||||
contactKey: widget.contact.publicKeyHex,
|
||||
contactName: widget.contact.name,
|
||||
senderName: message.isOutgoing
|
||||
? (context.read<MeshCoreConnector>().selfName ??
|
||||
context.l10n.chat_me)
|
||||
: contact.name,
|
||||
);
|
||||
unawaited(
|
||||
context.read<MeshCoreConnector>().setBookmarkedMessage(
|
||||
bookmark,
|
||||
isBookmarked: !message.isBookmarked,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (message.isOutgoing && message.status == MessageStatus.failed)
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
@@ -1571,12 +1632,14 @@ class _MessageBubble extends StatelessWidget {
|
||||
final void Function(Message message, String emoji)? onRetryReaction;
|
||||
final double textScale;
|
||||
final String sourceId;
|
||||
final bool isBookmarked;
|
||||
|
||||
const _MessageBubble({
|
||||
required this.message,
|
||||
required this.senderName,
|
||||
required this.sourceId,
|
||||
required this.textScale,
|
||||
required this.isBookmarked,
|
||||
this.onLongPress,
|
||||
this.onRetryReaction,
|
||||
});
|
||||
@@ -1669,6 +1732,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
child: MessageBubbleFrame(
|
||||
isOutgoing: isOutgoing,
|
||||
isFailed: isFailed,
|
||||
isBookmarked: isBookmarked,
|
||||
compact: gifId != null,
|
||||
maxWidth: constraints.maxWidth,
|
||||
child: Column(
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:meshcore_open/utils/gpx_export.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../utils/bookmark_markdown_export.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
import '../utils/share_origin.dart';
|
||||
import '../widgets/app_bar.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
@@ -12,6 +20,12 @@ import '../widgets/mesh_nav_tile.dart';
|
||||
import '../widgets/sync_progress_overlay.dart';
|
||||
|
||||
class ExportScreen extends StatelessWidget {
|
||||
static const _markdownFileType = XTypeGroup(
|
||||
label: 'Markdown',
|
||||
extensions: ['md'],
|
||||
mimeTypes: ['text/markdown'],
|
||||
);
|
||||
|
||||
const ExportScreen({super.key});
|
||||
|
||||
@override
|
||||
@@ -34,6 +48,16 @@ class ExportScreen extends StatelessWidget {
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 24),
|
||||
children: [
|
||||
SectionHeader(l10n.settings_export),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: MeshNavTile(
|
||||
icon: Icons.bookmark_border,
|
||||
title: l10n.settings_exportBookmarks,
|
||||
subtitle: l10n.settings_exportBookmarksSubtitle,
|
||||
onTap: () => _exportBookmarks(context),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
@@ -94,6 +118,78 @@ class ExportScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _exportBookmarks(BuildContext context) async {
|
||||
final l10n = context.l10n;
|
||||
try {
|
||||
final bookmarks = await context
|
||||
.read<MeshCoreConnector>()
|
||||
.loadBookmarkedMessages();
|
||||
if (!context.mounted) return;
|
||||
if (bookmarks.isEmpty) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_exportBookmarksNoBookmarks),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final exportedAt = DateTime.now();
|
||||
final markdown = await buildBookmarksMarkdown(
|
||||
bookmarks,
|
||||
publicGateway: context
|
||||
.read<AppSettingsService>()
|
||||
.settings
|
||||
.publicIpfsGateway,
|
||||
exportedAt: exportedAt,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
final date =
|
||||
'${exportedAt.year.toString().padLeft(4, '0')}'
|
||||
'-${exportedAt.month.toString().padLeft(2, '0')}'
|
||||
'-${exportedAt.day.toString().padLeft(2, '0')}';
|
||||
final filename = 'meshcore-open-bookmarks_$date.md';
|
||||
final file = XFile.fromData(
|
||||
Uint8List.fromList(utf8.encode(markdown)),
|
||||
name: filename,
|
||||
mimeType: 'text/markdown',
|
||||
);
|
||||
|
||||
if (PlatformInfo.isWeb) {
|
||||
await file.saveTo(filename);
|
||||
} else if (PlatformInfo.isDesktop) {
|
||||
final location = await getSaveLocation(
|
||||
suggestedName: filename,
|
||||
acceptedTypeGroups: const [_markdownFileType],
|
||||
);
|
||||
if (location == null || !context.mounted) return;
|
||||
await file.saveTo(location.path);
|
||||
} else {
|
||||
final result = await SharePlus.instance.share(
|
||||
ShareParams(
|
||||
subject: l10n.settings_exportBookmarks,
|
||||
files: [file],
|
||||
fileNameOverrides: [filename],
|
||||
sharePositionOrigin: shareOriginOf(context),
|
||||
),
|
||||
);
|
||||
if (result.status == ShareResultStatus.dismissed) return;
|
||||
}
|
||||
if (context.mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_exportBookmarksSuccess),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (context.mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text('${l10n.settings_gpxExportError} $error'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _gpxExport(
|
||||
BuildContext context,
|
||||
GpxExport exporter,
|
||||
|
||||
Reference in new issue
Block a user