Improve bookmarks navigation, scoping, search, and bulk actions

Add Bookmarks to the Contacts overflow menu, open the dedicated BookmarksScreen from direct and channel chat menus with a split scope pill (All vs current chat), add in-screen bookmark search with scroll-and-highlight jump, support bulk bookmarking from channel selection mode and bulk removal in BookmarksScreen, and prompt with a confirmation dialog before removing single or selected bookmarks.
This commit is contained in:
zjs81 committed 2026-11-23 18:20:19 -07:00
1 parent d4a6839413
commit 32977bdd50
32 files changed
+1817 -230

No files matched your search

+5 -1
View File
@@ -61,6 +61,7 @@ class LinkHandler {
TextStyle? coordinateStyle,
Color? backgroundColor,
VoidCallback? onSecondaryTap,
bool selectable = true,
}) {
return _InteractiveMessageText(
text: text,
@@ -69,6 +70,7 @@ class LinkHandler {
coordinateStyle: coordinateStyle,
backgroundColor: backgroundColor,
onSecondaryTap: onSecondaryTap,
selectable: selectable,
);
}
@@ -272,6 +274,7 @@ class _InteractiveMessageText extends StatefulWidget {
final TextStyle? coordinateStyle;
final Color? backgroundColor;
final VoidCallback? onSecondaryTap;
final bool selectable;
const _InteractiveMessageText({
required this.text,
@@ -280,6 +283,7 @@ class _InteractiveMessageText extends StatefulWidget {
this.coordinateStyle,
this.backgroundColor,
this.onSecondaryTap,
this.selectable = true,
});
@override
@@ -393,7 +397,7 @@ class _InteractiveMessageTextState extends State<_InteractiveMessageText> {
],
);
if (PlatformInfo.isDesktop) {
if (widget.selectable && PlatformInfo.isDesktop) {
final selectable = SelectableText.rich(span);
if (widget.onSecondaryTap == null) return selectable;
return Listener(
+11
View File
@@ -1230,6 +1230,17 @@
"bookmarks_channel": "Channel",
"bookmarks_contact": "Contact",
"bookmarks_remove": "Remove bookmark",
"bookmarks_removeConfirmTitle": "Remove Bookmark",
"bookmarks_removeConfirmMessage": "Remove this message from your bookmarks?",
"bookmarks_removeSelectedConfirmTitle": "Remove Bookmarks",
"bookmarks_removeSelectedConfirmMessage": "Remove {count} messages from your bookmarks?",
"@bookmarks_removeSelectedConfirmMessage": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"chat_selectMessages": "Select messages",
"chat_selectedCount": "{count} selected",
"@chat_selectedCount": {
+24
View File
@@ -4345,6 +4345,30 @@ abstract class AppLocalizations {
/// **'Remove bookmark'**
String get bookmarks_remove;
/// No description provided for @bookmarks_removeConfirmTitle.
///
/// In en, this message translates to:
/// **'Remove Bookmark'**
String get bookmarks_removeConfirmTitle;
/// No description provided for @bookmarks_removeConfirmMessage.
///
/// In en, this message translates to:
/// **'Remove this message from your bookmarks?'**
String get bookmarks_removeConfirmMessage;
/// No description provided for @bookmarks_removeSelectedConfirmTitle.
///
/// In en, this message translates to:
/// **'Remove Bookmarks'**
String get bookmarks_removeSelectedConfirmTitle;
/// No description provided for @bookmarks_removeSelectedConfirmMessage.
///
/// In en, this message translates to:
/// **'Remove {count} messages from your bookmarks?'**
String bookmarks_removeSelectedConfirmMessage(int count);
/// No description provided for @chat_selectMessages.
///
/// In en, this message translates to:
+15
View File
@@ -2474,6 +2474,21 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get bookmarks_remove => 'Премахни от отметките';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Избор на съобщения';
+15
View File
@@ -2460,6 +2460,21 @@ class AppLocalizationsCs extends AppLocalizations {
@override
String get bookmarks_remove => 'Odebrat záložku';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Vybrat zprávy';
+15
View File
@@ -2477,6 +2477,21 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get bookmarks_remove => 'Lesezeichen entfernen';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Nachrichten auswählen';
+15
View File
@@ -2430,6 +2430,21 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Select messages';
+15
View File
@@ -2468,6 +2468,21 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get bookmarks_remove => 'Quitar marcador';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Seleccionar mensajes';
+15
View File
@@ -2473,6 +2473,21 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get bookmarks_remove => 'Retirer des favoris';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Sélectionner des messages';
+15
View File
@@ -2465,6 +2465,21 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get bookmarks_remove => 'Könyvjelző eltávolítása';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Üzenetek kijelölése';
+15
View File
@@ -2470,6 +2470,21 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get bookmarks_remove => 'Rimuovi segnalibro';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Seleziona messaggi';
+15
View File
@@ -2355,6 +2355,21 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get bookmarks_remove => 'ブックマークを削除';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'メッセージを選択';
+15
View File
@@ -2357,6 +2357,21 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get bookmarks_remove => '북마크 삭제';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => '메시지 선택';
+15
View File
@@ -2455,6 +2455,21 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get bookmarks_remove => 'Bladwijzer verwijderen';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Berichten selecteren';
+15
View File
@@ -2488,6 +2488,21 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get bookmarks_remove => 'Usuń zakładkę';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Wybierz wiadomości';
+15
View File
@@ -2466,6 +2466,21 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get bookmarks_remove => 'Remover marcador';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Selecionar mensagens';
+15
View File
@@ -2469,6 +2469,21 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get bookmarks_remove => 'Убрать из закладок';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Выбрать сообщения';
+15
View File
@@ -2461,6 +2461,21 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get bookmarks_remove => 'Odstrániť záložku';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Vybrať správy';
+15
View File
@@ -2462,6 +2462,21 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get bookmarks_remove => 'Odstrani zaznamek';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Izberi sporočila';
+15
View File
@@ -2444,6 +2444,21 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get bookmarks_remove => 'Ta bort bokmärke';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Markera meddelanden';
+15
View File
@@ -2466,6 +2466,21 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get bookmarks_remove => 'Прибрати із закладок';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => 'Вибрати повідомлення';
+15
View File
@@ -2325,6 +2325,21 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get bookmarks_remove => '移除书签';
@override
String get bookmarks_removeConfirmTitle => 'Remove Bookmark';
@override
String get bookmarks_removeConfirmMessage =>
'Remove this message from your bookmarks?';
@override
String get bookmarks_removeSelectedConfirmTitle => 'Remove Bookmarks';
@override
String bookmarks_removeSelectedConfirmMessage(int count) {
return 'Remove $count messages from your bookmarks?';
}
@override
String get chat_selectMessages => '选择消息';
+578 -135
View File
@@ -1,17 +1,38 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import '../connector/meshcore_connector.dart';
import '../helpers/chat_jump.dart';
import '../helpers/message_search.dart';
import '../helpers/message_url_image_helper.dart';
import '../helpers/snack_bar_builder.dart';
import '../l10n/l10n.dart';
import '../models/bookmarked_message.dart';
import '../services/app_settings_service.dart';
import '../services/chat_text_scale_service.dart';
import '../theme/mesh_theme.dart';
import '../widgets/chat_search_results.dart';
import '../widgets/chat_send_pipeline.dart';
import '../widgets/empty_state.dart';
import '../widgets/mesh_ui.dart';
import '../widgets/translated_message_content.dart';
class BookmarksScreen extends StatefulWidget {
const BookmarksScreen({super.key});
final BookmarkSourceType? initialSourceType;
final String? initialSourceId;
final List<String> sourceIdAliases;
final String? initialSourceName;
const BookmarksScreen({
super.key,
this.initialSourceType,
this.initialSourceId,
this.sourceIdAliases = const [],
this.initialSourceName,
});
@override
State<BookmarksScreen> createState() => _BookmarksScreenState();
@@ -19,168 +40,590 @@ class BookmarksScreen extends StatefulWidget {
class _BookmarksScreenState extends State<BookmarksScreen> {
late Future<List<BookmarkedMessage>> _bookmarks;
List<BookmarkedMessage> _loadedBookmarks = const [];
late bool _filterToInitialSource;
final ScrollController _scrollController = ScrollController();
final TextEditingController _searchController = TextEditingController();
bool _searching = false;
String _searchQuery = '';
String? _highlightedStorageId;
Timer? _highlightTimer;
final Set<String> _selectedIds = <String>{};
bool get _hasInitialSource => widget.initialSourceId != null;
bool get _selecting => _selectedIds.isNotEmpty;
bool get _showSearchResults => _searching && _searchQuery.trim().isNotEmpty;
@override
void initState() {
super.initState();
_bookmarks = context.read<MeshCoreConnector>().loadBookmarkedMessages();
_filterToInitialSource = widget.initialSourceId != null;
_bookmarks = _fetchBookmarks();
}
@override
void dispose() {
_highlightTimer?.cancel();
_searchController.dispose();
_scrollController.dispose();
super.dispose();
}
Future<List<BookmarkedMessage>> _fetchBookmarks() async {
final loaded = await context
.read<MeshCoreConnector>()
.loadBookmarkedMessages();
if (mounted) {
_loadedBookmarks = loaded;
}
return loaded;
}
void _reload() {
setState(() {
_bookmarks = context.read<MeshCoreConnector>().loadBookmarkedMessages();
_bookmarks = _fetchBookmarks();
});
}
bool _matchesInitialSource(
BookmarkedMessage bookmark,
MeshCoreConnector connector,
) {
final sourceId = widget.initialSourceId;
if (sourceId == null) return true;
if (widget.initialSourceType != null &&
bookmark.sourceType != widget.initialSourceType) {
return false;
}
final validIds = <String>{sourceId, ...widget.sourceIdAliases};
if (bookmark.sourceType == BookmarkSourceType.channel) {
for (final channel in connector.channels) {
final slotId = 'slot:${channel.index}';
final storageId = channel.storageId;
if (validIds.contains(slotId) ||
(storageId != null && validIds.contains(storageId))) {
validIds.add(slotId);
if (storageId != null) validIds.add(storageId);
}
}
}
return validIds.contains(bookmark.sourceId);
}
List<BookmarkedMessage> _filteredBookmarks(
List<BookmarkedMessage> all,
MeshCoreConnector connector,
) {
final filtered = [
for (final bookmark in all)
if (!_hasInitialSource ||
!_filterToInitialSource ||
_matchesInitialSource(bookmark, connector))
bookmark,
];
filtered.sort((a, b) => a.receivedAt.compareTo(b.receivedAt));
return filtered;
}
void _openSearch() => setState(() => _searching = true);
void _closeSearch() {
_searchController.clear();
setState(() {
_searching = false;
_searchQuery = '';
});
}
Widget _buildSearchField() {
return CallbackShortcuts(
bindings: {
const SingleActivator(LogicalKeyboardKey.escape): _closeSearch,
},
child: TextField(
controller: _searchController,
autofocus: true,
textInputAction: TextInputAction.search,
style: const TextStyle(fontSize: 16),
decoration: InputDecoration(
hintText: context.l10n.chatSearch_hint,
border: InputBorder.none,
),
onChanged: (value) => setState(() => _searchQuery = value),
),
);
}
Future<List<ChatSearchEntry>> _loadSearchEntries() async {
final connector = context.read<MeshCoreConnector>();
final all = await connector.loadBookmarkedMessages();
if (mounted) {
_loadedBookmarks = all;
}
final visible = _filteredBookmarks(all, connector);
return [
for (final bookmark in visible)
ChatSearchEntry(
id: bookmark.storageId,
sender: '${bookmark.senderName} · ${bookmark.sourceName}',
text: bookmark.text,
translatedText: bookmark.translatedText,
time: bookmark.receivedAt,
matchSender: true,
),
];
}
Future<void> _jumpToSearchResult(String storageId) async {
FocusScope.of(context).unfocus();
_closeSearch();
await WidgetsBinding.instance.endOfFrame;
if (!mounted) return;
final connector = context.read<MeshCoreConnector>();
final visible = _filteredBookmarks(_loadedBookmarks, connector);
final index = visible.indexWhere((b) => b.storageId == storageId);
if (index < 0) {
showDismissibleSnackBar(
context,
content: Text(context.l10n.chatSearch_jumpFailed),
);
return;
}
final targetIndex = visible.length - 1 - index;
if (_scrollController.hasClients) {
await scrollListToIndex(
controller: _scrollController,
targetIndex: targetIndex,
itemCount: visible.length,
isMounted: () => mounted,
);
}
if (!mounted) return;
_highlightTimer?.cancel();
setState(() => _highlightedStorageId = storageId);
_highlightTimer = Timer(const Duration(seconds: 2), () {
if (mounted) setState(() => _highlightedStorageId = null);
});
}
void _toggleSelected(BookmarkedMessage bookmark) {
HapticFeedback.selectionClick();
setState(() {
if (!_selectedIds.remove(bookmark.storageId)) {
_selectedIds.add(bookmark.storageId);
}
});
}
void _clearSelection() => setState(_selectedIds.clear);
Future<void> _remove(BookmarkedMessage bookmark) async {
final confirmed = await confirmRemoveBookmarks(context);
if (!confirmed || !mounted) return;
await context.read<MeshCoreConnector>().setBookmarkedMessage(
bookmark,
isBookmarked: false,
);
if (!mounted) return;
_selectedIds.remove(bookmark.storageId);
_reload();
}
Future<void> _removeSelected() async {
if (_selectedIds.isEmpty) return;
final connector = context.read<MeshCoreConnector>();
final visible = _filteredBookmarks(_loadedBookmarks, connector);
final toRemove = [
for (final bookmark in visible)
if (_selectedIds.contains(bookmark.storageId)) bookmark,
];
final count = toRemove.isNotEmpty ? toRemove.length : _selectedIds.length;
final confirmed = await confirmRemoveBookmarks(context, count: count);
if (!confirmed || !mounted) return;
final targets = toRemove.isNotEmpty
? toRemove
: [
for (final bookmark in _loadedBookmarks)
if (_selectedIds.contains(bookmark.storageId)) bookmark,
];
_clearSelection();
for (final bookmark in targets) {
await connector.setBookmarkedMessage(bookmark, isBookmarked: false);
}
if (mounted) _reload();
}
PreferredSizeWidget _buildSelectionAppBar(BuildContext context) {
final l10n = context.l10n;
return AppBar(
leading: IconButton(
tooltip: l10n.chat_clearSelection,
icon: const Icon(Icons.close),
onPressed: _clearSelection,
),
title: Text(l10n.chat_selectedCount(_selectedIds.length)),
centerTitle: false,
actions: [
IconButton(
tooltip: l10n.bookmarks_remove,
icon: const Icon(Icons.delete_outline),
onPressed: _selectedIds.isEmpty ? null : _removeSelected,
),
],
);
}
Widget _buildScopePill(BuildContext context) {
final sourceLabel =
(widget.initialSourceName != null &&
widget.initialSourceName!.trim().isNotEmpty)
? widget.initialSourceName!
: widget.initialSourceId!;
return Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
child: SizedBox(
width: double.infinity,
child: SegmentedButton<bool>(
showSelectedIcon: false,
style: SegmentedButton.styleFrom(
minimumSize: const Size(48, 48),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(MeshRadii.pill),
),
),
segments: [
ButtonSegment<bool>(
value: false,
label: MeshSegmentLabel(context.l10n.listFilter_all),
),
ButtonSegment<bool>(
value: true,
label: MeshSegmentLabel(sourceLabel),
),
],
selected: {_filterToInitialSource},
onSelectionChanged: (selection) {
setState(() {
_filterToInitialSource = selection.first;
_selectedIds.clear();
});
},
),
),
);
}
Widget _buildSelectableRow(BookmarkedMessage bookmark, Widget cardBody) {
final scheme = Theme.of(context).colorScheme;
final selected = _selectedIds.contains(bookmark.storageId);
return Semantics(
selected: selected,
button: true,
child: Material(
color: selected
? scheme.primary.withValues(alpha: 0.16)
: Colors.transparent,
borderRadius: BorderRadius.circular(MeshRadii.md),
child: InkWell(
borderRadius: BorderRadius.circular(MeshRadii.md),
onTap: () => _toggleSelected(bookmark),
onLongPress: () => _toggleSelected(bookmark),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 4),
child: Row(
children: [
Icon(
selected ? Icons.check_circle : Icons.radio_button_unchecked,
size: 28,
color: selected ? scheme.primary : scheme.onSurfaceVariant,
),
const SizedBox(width: 8),
Expanded(child: AbsorbPointer(child: cardBody)),
],
),
),
),
),
);
}
@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
final publicIpfsGateway =
context.watch<AppSettingsService?>()?.settings.publicIpfsGateway ?? '';
final textScale = context.watch<ChatTextScaleService?>()?.scale ?? 1.0;
return PopScope(
canPop: !_searching && !_selecting,
onPopInvokedWithResult: (didPop, _) {
if (didPop) return;
if (_selecting) {
_clearSelection();
} else if (_searching) {
_closeSearch();
}
},
child: Scaffold(
appBar: _selecting
? _buildSelectionAppBar(context)
: AppBar(
leading: _searching
? IconButton(
tooltip: l10n.chatSearch_close,
icon: const Icon(Icons.arrow_back),
onPressed: _closeSearch,
)
: null,
title: _searching
? _buildSearchField()
: Text(l10n.bookmarks_title),
centerTitle: !_searching,
actions: _searching
? null
: bookmark.text,
style: textStyle,
originalStyle: textStyle.copyWith(fontStyle: FontStyle.italic),
backgroundColor:
Theme.of(context).cardTheme.color ??
Theme.of(context).colorScheme.surfaceContainerLow,
);
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,
: [
IconButton(
tooltip: l10n.chatSearch_tooltip,
icon: const Icon(Icons.search),
onPressed: _openSearch,
),
],
),
body: Column(
children: [
if (_hasInitialSource) _buildScopePill(context),
Expanded(
child: _showSearchResults
? ChatSearchResults(
key: ValueKey<bool>(_filterToInitialSource),
query: _searchQuery.trim(),
loadEntries: _loadSearchEntries,
textScale: textScale,
onSelect: (entry) =>
unawaited(_jumpToSearchResult(entry.id)),
)
: FutureBuilder<List<BookmarkedMessage>>(
future: _bookmarks,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const Center(
child: CircularProgressIndicator(),
);
}
final connector = context.watch<MeshCoreConnector>();
final allBookmarks =
snapshot.data ?? const <BookmarkedMessage>[];
_loadedBookmarks = allBookmarks;
final bookmarks = _filteredBookmarks(
allBookmarks,
connector,
);
if (bookmarks.isEmpty) {
return EmptyState(
icon: Icons.bookmark_border,
title: l10n.bookmarks_empty,
);
}
return ListView.builder(
controller: _scrollController,
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 scheme = Theme.of(context).colorScheme;
final baseCardColor =
Theme.of(context).cardTheme.color ??
scheme.surfaceContainerLow;
final highlighted =
bookmark.storageId == _highlightedStorageId;
final cardColor = highlighted
? Color.alphaBlend(
scheme.primary.withValues(alpha: 0.18),
baseCardColor,
)
: baseCardColor;
final textContent = TranslatedMessageContent(
displayText: displayText,
originalText: displayText == bookmark.text
? null
: bookmark.text,
style: textStyle,
originalStyle: textStyle.copyWith(
fontStyle: FontStyle.italic,
),
backgroundColor: cardColor,
selectable: false,
);
final card = Card(
margin: EdgeInsets.zero,
color: cardColor,
child: InkWell(
borderRadius: BorderRadius.circular(
MeshRadii.md,
),
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,
onLongPress: _selecting
? null
: () => _toggleSelected(bookmark),
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,
],
),
),
textContent,
],
),
);
final highlightedCard = highlighted
? AnimatedContainer(
duration: const Duration(milliseconds: 300),
decoration: BoxDecoration(
color: scheme.primary.withValues(
alpha: 0.18,
),
borderRadius: BorderRadius.circular(
MeshRadii.md,
),
),
child: card,
)
: card;
return Padding(
padding: const EdgeInsets.only(bottom: 10),
child: _selecting
? _buildSelectableRow(
bookmark,
highlightedCard,
)
: highlightedCard,
);
},
)
else
textContent,
],
),
),
);
},
);
},
);
},
),
),
],
),
),
);
}
+70 -43
View File
@@ -75,6 +75,7 @@ import '../widgets/mesh_ui.dart';
import '../widgets/share_contact_sheet.dart';
import '../widgets/shared_contact_card.dart';
import 'app_settings_screen.dart';
import 'bookmarks_screen.dart';
import 'channel_chat_transcript_grouping.dart';
import 'channels_screen.dart' show confirmDeleteChannel, showEditChannelSheet;
import 'channel_message_path_screen.dart';
@@ -178,7 +179,6 @@ 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
@@ -609,10 +609,27 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
onSaved: _onChannelEdited,
);
case 'showBookmarks':
setState(() {
_showBookmarkedOnly = !_showBookmarkedOnly;
_selectedIds.clear();
});
final channelLabel = widget.channel.name.isEmpty
? '#${context.l10n.channels_channelIndex(widget.channel.index)}'
: (widget.channel.name.startsWith('#')
? widget.channel.name
: '#${widget.channel.name}');
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => BookmarksScreen(
initialSourceType: BookmarkSourceType.channel,
initialSourceId:
widget.channel.storageId ??
'slot:${widget.channel.index}',
sourceIdAliases: [
?widget.channel.storageId,
'slot:${widget.channel.index}',
],
initialSourceName: channelLabel,
),
),
);
case 'background':
showChatBackgroundSheet(
context,
@@ -671,9 +688,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
PopupMenuItem(
value: 'showBookmarks',
child: _menuRow(
_showBookmarkedOnly ? Icons.bookmark : Icons.bookmark_border,
context.l10n.chat_showBookmarks,
color: _showBookmarkedOnly ? const Color(0xFFFFE54A) : null,
Icons.bookmark_border,
context.l10n.bookmarks_title,
),
),
PopupMenuItem(
@@ -908,22 +924,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
final layout = _transcriptLayoutFor(
context,
messages,
showBookmarkedOnly: _showBookmarkedOnly,
);
// Fewer entries than messages means the message filter
// hid or collapsed some; bookmark filtering is deliberate.
final hidesMessages =
!_showBookmarkedOnly &&
layout.length < messages.length;
// hid or collapsed some.
final hidesMessages = 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(
@@ -1243,7 +1250,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
: null,
child: MessageBubbleFrame(
isOutgoing: isOutgoing,
isBookmarked: message.isBookmarked || _showBookmarkedOnly,
isBookmarked: message.isBookmarked,
compact: gifId != null,
maxWidth: constraints.maxWidth,
child: Column(
@@ -2285,9 +2292,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
/// `State`'s) — `watch` asserts on that.
_TranscriptLayout _transcriptLayoutFor(
BuildContext context,
List<ChannelMessage> messages, {
bool showBookmarkedOnly = false,
}) {
List<ChannelMessage> messages,
) {
ReceivedImageStore? store;
try {
store = context.watch<ReceivedImageStore>();
@@ -2316,7 +2322,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
displayMode,
filterActive,
_revealVersion,
showBookmarkedOnly,
_filteredMessagesSignature(messages),
Object.hashAll(
messages
@@ -2325,8 +2330,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
),
);
final cached = _transcriptLayout;
if (!showBookmarkedOnly &&
cached != null &&
if (cached != null &&
cached.matches(
messages,
_imageStoreVersion,
@@ -2335,14 +2339,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
)) {
return cached;
}
final displayedMessages = showBookmarkedOnly
? messages.where((message) => message.isBookmarked).toList()
: messages;
final images = store == null || showBookmarkedOnly
final images = store == null
? const <ReceivedImageEntry>[]
: store.entriesForChannel(widget.channel.storageId);
final layout = _TranscriptLayout.build(
messages: displayedMessages,
messages: messages,
images: images,
imageVersion: _imageStoreVersion,
channelIndex: widget.channel.index,
@@ -3188,8 +3189,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
? context.l10n.chat_removeBookmark
: context.l10n.chat_bookmark,
),
onTap: () {
onTap: () async {
final connector = context.read<MeshCoreConnector>();
final selfLabel = connector.selfName ?? context.l10n.chat_me;
Navigator.pop(sheetContext);
if (message.isBookmarked) {
final confirmed = await confirmRemoveBookmarks(context);
if (!confirmed || !mounted) return;
}
final bookmark = BookmarkedMessage.fromChannel(
message: message,
channelId:
@@ -3197,15 +3204,12 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
'slot:${widget.channel.index}',
channelName: widget.channel.name,
senderName: message.isOutgoing
? (context.read<MeshCoreConnector>().selfName ??
context.l10n.chat_me)
? selfLabel
: message.senderName,
);
unawaited(
context.read<MeshCoreConnector>().setBookmarkedMessage(
bookmark,
isBookmarked: !message.isBookmarked,
),
await connector.setBookmarkedMessage(
bookmark,
isBookmarked: !message.isBookmarked,
);
},
),
@@ -3309,10 +3313,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
final filterActive = _transcriptLayout?.filterActive ?? true;
return [
for (final m in messages)
if ((!_showBookmarkedOnly || m.isBookmarked) &&
!(filterActive &&
m.isFiltered &&
!_revealedFilteredIds.contains(m.messageId)))
if (!(filterActive &&
m.isFiltered &&
!_revealedFilteredIds.contains(m.messageId)))
m,
];
}
@@ -3391,6 +3394,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
icon: const Icon(Icons.visibility_outlined),
onPressed: () => _bulkMarkNotSpam(notSpamCandidates),
),
IconButton(
tooltip: l10n.chat_bookmark,
icon: const Icon(Icons.bookmark_add_outlined),
onPressed: selected.isEmpty ? null : () => _bulkBookmark(selected),
),
IconButton(
tooltip: l10n.common_delete,
icon: const Icon(Icons.delete_outline),
@@ -3465,6 +3473,25 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
showDismissibleSnackBar(context, content: Text(text));
}
Future<void> _bulkBookmark(List<ChannelMessage> messages) async {
final connector = context.read<MeshCoreConnector>();
final selfLabel = connector.selfName ?? context.l10n.chat_me;
final channelId =
widget.channel.storageId ?? 'slot:${widget.channel.index}';
final channelName = widget.channel.name;
final toBookmark = messages.where((m) => !m.isBookmarked).toList();
_clearSelection();
for (final message in toBookmark) {
final bookmark = BookmarkedMessage.fromChannel(
message: message,
channelId: channelId,
channelName: channelName,
senderName: message.isOutgoing ? selfLabel : message.senderName,
);
await connector.setBookmarkedMessage(bookmark, isBookmarked: true);
}
}
Future<void> _bulkDelete(List<ChannelMessage> messages) async {
final connector = context.read<MeshCoreConnector>();
final confirmed = await confirmBulkDelete(context, messages.length);
+32 -45
View File
@@ -44,6 +44,7 @@ import '../widgets/chat_zoom_wrapper.dart';
import '../widgets/message_bubble_frame.dart';
import '../widgets/reaction_chips.dart';
import '../widgets/chat_day_separator.dart';
import 'bookmarks_screen.dart';
import 'channel_message_path_screen.dart';
import 'contacts_screen.dart' show confirmRemoveContact;
import 'map_screen.dart';
@@ -97,13 +98,12 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
final _textController = TextEditingController();
final _scrollController = ChatScrollController();
final _scrollAnchor = ChatScrollAnchor();
({String id, bool bookmarksOnly})? _newestRow;
String? _newestRowId;
final _textFieldFocusNode = FocusNode();
bool _focusLostWhileAway = false;
bool _focusLostToRoute = false;
final GlobalKey _unreadScrollKey = GlobalKey();
bool _isLoadingOlder = false;
bool _showBookmarkedOnly = false;
MeshCoreConnector? _connector;
Message? _pendingUnreadScrollTarget;
String? _unreadDividerMessageId;
@@ -513,8 +513,15 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
case 'settings':
_showContactSettings(context);
case 'showBookmarks':
setState(
() => _showBookmarkedOnly = !_showBookmarkedOnly,
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => BookmarksScreen(
initialSourceType: BookmarkSourceType.contact,
initialSourceId: widget.contact.publicKeyHex,
initialSourceName: contact.name,
),
),
);
case 'background':
showChatBackgroundSheet(
@@ -586,13 +593,8 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
PopupMenuItem(
value: 'showBookmarks',
child: MeshMenuItemRow(
icon: _showBookmarkedOnly
? Icons.bookmark
: Icons.bookmark_border,
label: context.l10n.chat_showBookmarks,
color: _showBookmarkedOnly
? const Color(0xFFFFE54A)
: null,
icon: Icons.bookmark_border,
label: context.l10n.bookmarks_title,
),
),
PopupMenuItem(
@@ -697,7 +699,6 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
}
Widget _buildEmptyState() {
if (_showBookmarkedOnly) return _buildBookmarkEmptyState();
return EmptyState(
icon: Icons.chat_bubble_outline,
title: context.l10n.chat_noMessages,
@@ -707,40 +708,25 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
);
}
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 = visibleMessages.reversed.toList();
final reversedMessages = messages.reversed.toList();
final itemCount = reversedMessages.length + (_isLoadingOlder ? 1 : 0);
// A reader scrolled up keeps their place when messages arrive below, as
// a room's backlog does in a burst right after login.
final previous = _newestRow;
final newest = (
id: reversedMessages.first.messageId,
bookmarksOnly: _showBookmarkedOnly,
);
_newestRow = newest;
if (previous != null &&
previous.bookmarksOnly == newest.bookmarksOnly &&
previous.id != newest.id &&
final previousId = _newestRowId;
final newestId = reversedMessages.first.messageId;
_newestRowId = newestId;
if (previousId != null &&
previousId != newestId &&
_pendingUnreadScrollTarget == null &&
_scrollController.showJumpToBottom.value) {
final inserted = reversedMessages.indexWhere(
(m) => m.messageId == previous.id,
(m) => m.messageId == previousId,
);
if (inserted > 0) _scrollAnchor.rowsInsertedBelow(inserted);
}
@@ -825,7 +811,7 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
: contact.name,
sourceId: widget.contact.publicKeyHex,
textScale: textScale,
isBookmarked: message.isBookmarked || _showBookmarkedOnly,
isBookmarked: message.isBookmarked,
onLongPress: () => _showMessageActions(message, contact),
onRetryReaction: (msg, emoji) =>
_sendReaction(msg, contact, emoji),
@@ -1488,22 +1474,23 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
? context.l10n.chat_removeBookmark
: context.l10n.chat_bookmark,
),
onTap: () {
onTap: () async {
final connector = context.read<MeshCoreConnector>();
final selfLabel = connector.selfName ?? context.l10n.chat_me;
Navigator.pop(sheetContext);
if (message.isBookmarked) {
final confirmed = await confirmRemoveBookmarks(context);
if (!confirmed || !mounted) return;
}
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,
senderName: message.isOutgoing ? selfLabel : contact.name,
);
unawaited(
context.read<MeshCoreConnector>().setBookmarkedMessage(
bookmark,
isBookmarked: !message.isBookmarked,
),
await connector.setBookmarkedMessage(
bookmark,
isBookmarked: !message.isBookmarked,
);
},
),
+11
View File
@@ -37,6 +37,7 @@ import '../widgets/sync_progress_overlay.dart';
import '../widgets/unread_badge.dart';
import '../helpers/snack_bar_builder.dart';
import 'add_contact_screen.dart';
import 'bookmarks_screen.dart';
import 'channels_screen.dart';
import 'chat_screen.dart';
import 'discovery_screen.dart';
@@ -384,6 +385,16 @@ class _ContactsScreenState extends State<ContactsScreen> {
MaterialPageRoute(builder: (_) => const DiscoveryScreen()),
),
),
PopupMenuItem(
child: MeshMenuItemRow(
icon: Icons.bookmark_border,
label: menuContext.l10n.bookmarks_title,
),
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const BookmarksScreen()),
),
),
const PopupMenuDivider(),
PopupMenuItem(
enabled: !readOnly,
+13 -4
View File
@@ -13,11 +13,11 @@ class BookmarkStore {
String get keyFor => '$_keyPrefix$publicKeyHex';
Future<void> _pendingWrites = Future<void>.value();
Future<void>? _pendingWrites;
Future<List<BookmarkedMessage>> loadBookmarks() async {
final writes = _pendingWrites;
await writes;
if (writes != null) await writes;
return _readBookmarks(keyFor);
}
@@ -47,11 +47,20 @@ class BookmarkStore {
}
Future<void> _enqueue(Future<void> Function() operation) {
final next = _pendingWrites.then((_) => operation());
_pendingWrites = next.then<void>(
final previous = _pendingWrites;
final next = previous == null
? Future<void>.sync(operation)
: previous.then((_) => operation());
final completion = next.then<void>(
(_) {},
onError: (Object _, StackTrace _) {},
);
_pendingWrites = completion;
completion.whenComplete(() {
if (identical(_pendingWrites, completion)) {
_pendingWrites = null;
}
});
return next;
}
+39
View File
@@ -219,3 +219,42 @@ Future<bool> confirmClearChat(
);
return confirmed == true;
}
/// Asks before removing [count] bookmarked messages.
Future<bool> confirmRemoveBookmarks(
BuildContext context, {
int count = 1,
}) async {
final confirmed = await showDialog<bool>(
context: context,
builder: (dialogContext) {
final l10n = dialogContext.l10n;
return AlertDialog(
title: Text(
count == 1
? l10n.bookmarks_removeConfirmTitle
: l10n.bookmarks_removeSelectedConfirmTitle,
),
content: Text(
count == 1
? l10n.bookmarks_removeConfirmMessage
: l10n.bookmarks_removeSelectedConfirmMessage(count),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogContext, false),
child: Text(l10n.common_cancel),
),
TextButton(
onPressed: () => Navigator.pop(dialogContext, true),
style: TextButton.styleFrom(
foregroundColor: Theme.of(dialogContext).colorScheme.error,
),
child: Text(l10n.common_remove),
),
],
);
},
);
return confirmed == true;
}
@@ -10,6 +10,7 @@ class TranslatedMessageContent extends StatelessWidget {
final Color? backgroundColor;
final bool showOriginalFirst;
final VoidCallback? onSecondaryTap;
final bool selectable;
const TranslatedMessageContent({
super.key,
@@ -20,6 +21,7 @@ class TranslatedMessageContent extends StatelessWidget {
this.backgroundColor,
this.showOriginalFirst = true,
this.onSecondaryTap,
this.selectable = true,
});
@override
@@ -42,6 +44,7 @@ class TranslatedMessageContent extends StatelessWidget {
),
backgroundColor: backgroundColor,
onSecondaryTap: onSecondaryTap,
selectable: selectable,
)
: null;
final translatedWidget = LinkHandler.buildLinkifyText(
@@ -50,6 +53,7 @@ class TranslatedMessageContent extends StatelessWidget {
style: style,
backgroundColor: backgroundColor,
onSecondaryTap: onSecondaryTap,
selectable: selectable,
);
if (!shouldShowOriginal) {