Save Bookmark with Bookmark overview in channel menu, and bookmark-filter in channel and contact.

This commit is contained in:
ericz committed 2026-11-13 23:06:17 +01:00
1 parent c0702806de
commit f32300797e
39 files changed
+1556 -25

No files matched your search

+178
View File
@@ -0,0 +1,178 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.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;
final dateFormat = DateFormat.yMd(
Localizations.localeOf(context).toString(),
).add_Hm();
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) => b.receivedAt.compareTo(a.receivedAt));
return ListView.builder(
padding: const EdgeInsets.all(12),
itemCount: bookmarks.length,
itemBuilder: (context, index) {
final bookmark = bookmarks[index];
final sourceType =
bookmark.sourceType == BookmarkSourceType.channel
? l10n.bookmarks_channel
: l10n.bookmarks_contact;
final time = dateFormat.format(bookmark.receivedAt.toLocal());
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} · $time',
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,
],
),
),
);
},
);
},
),
);
}
}
+80 -11
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;
@@ -165,6 +166,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
@@ -574,6 +576,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
widget.channel,
onSaved: _onChannelEdited,
);
case 'showBookmarks':
setState(() {
_showBookmarkedOnly = !_showBookmarkedOnly;
_selectedIds.clear();
});
case 'background':
showChatBackgroundSheet(
context,
@@ -629,6 +636,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),
@@ -856,13 +871,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(
@@ -1167,6 +1191,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
: null,
child: MessageBubbleFrame(
isOutgoing: isOutgoing,
isBookmarked: message.isBookmarked || _showBookmarkedOnly,
compact: gifId != null,
maxWidth: constraints.maxWidth,
child: Column(
@@ -2187,8 +2212,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>();
@@ -2217,10 +2243,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,
@@ -2229,11 +2262,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,
@@ -2994,6 +3030,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)
@@ -3094,9 +3162,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,
];
}
+11
View File
@@ -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,
+65 -1
View File
@@ -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';
@@ -96,6 +97,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;
@@ -484,6 +486,10 @@ class _ChatScreenState extends State<ChatScreen> {
_showContactInfo(context);
case 'settings':
_showContactSettings(context);
case 'showBookmarks':
setState(
() => _showBookmarkedOnly = !_showBookmarkedOnly,
);
case 'background':
showChatBackgroundSheet(
context,
@@ -551,6 +557,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(
@@ -631,6 +649,7 @@ class _ChatScreenState extends State<ChatScreen> {
}
Widget _buildEmptyState() {
if (_showBookmarkedOnly) return _buildBookmarkEmptyState();
return EmptyState(
icon: Icons.chat_bubble_outline,
title: context.l10n.chat_noMessages,
@@ -640,12 +659,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
@@ -713,6 +743,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),
@@ -1457,6 +1488,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,
@@ -1567,12 +1628,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,
});
@@ -1664,6 +1727,7 @@ class _MessageBubble extends StatelessWidget {
child: MessageBubbleFrame(
isOutgoing: isOutgoing,
isFailed: isFailed,
isBookmarked: isBookmarked,
compact: gifId != null,
maxWidth: constraints.maxWidth,
child: Column(