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:
1 parent
d4a6839413
commit
32977bdd50
32 files changed
+1817
-230
No files matched your search
@@ -155,7 +155,7 @@ Icon sizes in use: 24 for tile and banner icons, 20 for menu icons and small act
|
|||||||
- `FilledButton.tonal`: a secondary action that still needs weight (rare).
|
- `FilledButton.tonal`: a secondary action that still needs weight (rare).
|
||||||
- `OutlinedButton(.icon)`: secondary actions next to a filled one.
|
- `OutlinedButton(.icon)`: secondary actions next to a filled one.
|
||||||
- `TextButton`: Cancel and low-emphasis actions in dialogs; inline actions in cards.
|
- `TextButton`: Cancel and low-emphasis actions in dialogs; inline actions in cards.
|
||||||
- Destructive confirm: `FilledButton` with `backgroundColor: scheme.error`, `foregroundColor: scheme.onError` (`showConfirmClearDialog` in `widgets/confirm_clear_dialog.dart`), or a `TextButton` with `foregroundColor: scheme.error` when it is not the primary action.
|
- Destructive confirm: destructive or data-removing actions (such as clearing a chat, deleting a channel or contact, or removing single or bulk bookmarks) always prompt with a confirmation `AlertDialog` pairing a `Cancel` `TextButton` with an error-styled destructive action (`TextButton` with `foregroundColor: scheme.error`, as in `confirmClearChat` and `confirmRemoveBookmarks`, or `FilledButton` with `backgroundColor: scheme.error`, `foregroundColor: scheme.onError`).
|
||||||
- Dialog action order: Cancel first, primary last.
|
- Dialog action order: Cancel first, primary last.
|
||||||
- Avoid `ElevatedButton` in new code.
|
- Avoid `ElevatedButton` in new code.
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@ What the code does:
|
|||||||
Rules for new UI:
|
Rules for new UI:
|
||||||
|
|
||||||
1. **Settings → page.** A row in Settings, App Settings or a repeater screen that opens settings opens a page, even for a single field. See [Settings pages](#settings-pages).
|
1. **Settings → page.** A row in Settings, App Settings or a repeater screen that opens settings opens a page, even for a single field. See [Settings pages](#settings-pages).
|
||||||
2. **Confirmation or a single short input → dialog.** Title, one sentence, Cancel + one action. Inside settings, dialogs only confirm actions (Reboot, Delete all paths, unsaved changes).
|
2. **Confirmation or a single short input → dialog.** Title, one sentence, Cancel + one action. Destructive or data-removing actions (clearing a chat, deleting a channel/contact, or removing single/bulk bookmarks) always use this `AlertDialog` pattern (`Cancel` + `scheme.error` destructive action button). Inside settings, dialogs only confirm actions (Reboot, Delete all paths, unsaved changes).
|
||||||
3. **Pick one of several options, or act on one item → sheet.** Use `showMeshSheet` and start the content with `BottomSheetHeader(title:, subtitle:)`. It handles the keyboard and navigation-bar insets. Use raw `showModalBottomSheet` only when you need `DraggableScrollableSheet`.
|
3. **Pick one of several options, or act on one item → sheet.** Use `showMeshSheet` and start the content with `BottomSheetHeader(title:, subtitle:)`. It handles the keyboard and navigation-bar insets. Use raw `showModalBottomSheet` only when you need `DraggableScrollableSheet`.
|
||||||
4. **Forms with sections, live remote values, or anything that needs Save/Discard → page.** Guard unsaved changes with `UnsavedChangesGuard` (built into `SaveToRadioPage`).
|
4. **Forms with sections, live remote values, or anything that needs Save/Discard → page.** Guard unsaved changes with `UnsavedChangesGuard` (built into `SaveToRadioPage`).
|
||||||
5. Never stack a dialog on a sheet on a dialog. Close the sheet first, or move the flow to a page.
|
5. Never stack a dialog on a sheet on a dialog. Close the sheet first, or move the flow to a page.
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class LinkHandler {
|
|||||||
TextStyle? coordinateStyle,
|
TextStyle? coordinateStyle,
|
||||||
Color? backgroundColor,
|
Color? backgroundColor,
|
||||||
VoidCallback? onSecondaryTap,
|
VoidCallback? onSecondaryTap,
|
||||||
|
bool selectable = true,
|
||||||
}) {
|
}) {
|
||||||
return _InteractiveMessageText(
|
return _InteractiveMessageText(
|
||||||
text: text,
|
text: text,
|
||||||
@@ -69,6 +70,7 @@ class LinkHandler {
|
|||||||
coordinateStyle: coordinateStyle,
|
coordinateStyle: coordinateStyle,
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
onSecondaryTap: onSecondaryTap,
|
onSecondaryTap: onSecondaryTap,
|
||||||
|
selectable: selectable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,6 +274,7 @@ class _InteractiveMessageText extends StatefulWidget {
|
|||||||
final TextStyle? coordinateStyle;
|
final TextStyle? coordinateStyle;
|
||||||
final Color? backgroundColor;
|
final Color? backgroundColor;
|
||||||
final VoidCallback? onSecondaryTap;
|
final VoidCallback? onSecondaryTap;
|
||||||
|
final bool selectable;
|
||||||
|
|
||||||
const _InteractiveMessageText({
|
const _InteractiveMessageText({
|
||||||
required this.text,
|
required this.text,
|
||||||
@@ -280,6 +283,7 @@ class _InteractiveMessageText extends StatefulWidget {
|
|||||||
this.coordinateStyle,
|
this.coordinateStyle,
|
||||||
this.backgroundColor,
|
this.backgroundColor,
|
||||||
this.onSecondaryTap,
|
this.onSecondaryTap,
|
||||||
|
this.selectable = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -393,7 +397,7 @@ class _InteractiveMessageTextState extends State<_InteractiveMessageText> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (PlatformInfo.isDesktop) {
|
if (widget.selectable && PlatformInfo.isDesktop) {
|
||||||
final selectable = SelectableText.rich(span);
|
final selectable = SelectableText.rich(span);
|
||||||
if (widget.onSecondaryTap == null) return selectable;
|
if (widget.onSecondaryTap == null) return selectable;
|
||||||
return Listener(
|
return Listener(
|
||||||
|
|||||||
@@ -1230,6 +1230,17 @@
|
|||||||
"bookmarks_channel": "Channel",
|
"bookmarks_channel": "Channel",
|
||||||
"bookmarks_contact": "Contact",
|
"bookmarks_contact": "Contact",
|
||||||
"bookmarks_remove": "Remove bookmark",
|
"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_selectMessages": "Select messages",
|
||||||
"chat_selectedCount": "{count} selected",
|
"chat_selectedCount": "{count} selected",
|
||||||
"@chat_selectedCount": {
|
"@chat_selectedCount": {
|
||||||
|
|||||||
@@ -4345,6 +4345,30 @@ abstract class AppLocalizations {
|
|||||||
/// **'Remove bookmark'**
|
/// **'Remove bookmark'**
|
||||||
String get bookmarks_remove;
|
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.
|
/// No description provided for @chat_selectMessages.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
|
|||||||
@@ -2474,6 +2474,21 @@ class AppLocalizationsBg extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Премахни от отметките';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Избор на съобщения';
|
String get chat_selectMessages => 'Избор на съобщения';
|
||||||
|
|
||||||
|
|||||||
@@ -2460,6 +2460,21 @@ class AppLocalizationsCs extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Odebrat záložku';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Vybrat zprávy';
|
String get chat_selectMessages => 'Vybrat zprávy';
|
||||||
|
|
||||||
|
|||||||
@@ -2477,6 +2477,21 @@ class AppLocalizationsDe extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Lesezeichen entfernen';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Nachrichten auswählen';
|
String get chat_selectMessages => 'Nachrichten auswählen';
|
||||||
|
|
||||||
|
|||||||
@@ -2430,6 +2430,21 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Remove bookmark';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Select messages';
|
String get chat_selectMessages => 'Select messages';
|
||||||
|
|
||||||
|
|||||||
@@ -2468,6 +2468,21 @@ class AppLocalizationsEs extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Quitar marcador';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Seleccionar mensajes';
|
String get chat_selectMessages => 'Seleccionar mensajes';
|
||||||
|
|
||||||
|
|||||||
@@ -2473,6 +2473,21 @@ class AppLocalizationsFr extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Retirer des favoris';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Sélectionner des messages';
|
String get chat_selectMessages => 'Sélectionner des messages';
|
||||||
|
|
||||||
|
|||||||
@@ -2465,6 +2465,21 @@ class AppLocalizationsHu extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Könyvjelző eltávolítása';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Üzenetek kijelölése';
|
String get chat_selectMessages => 'Üzenetek kijelölése';
|
||||||
|
|
||||||
|
|||||||
@@ -2470,6 +2470,21 @@ class AppLocalizationsIt extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Rimuovi segnalibro';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Seleziona messaggi';
|
String get chat_selectMessages => 'Seleziona messaggi';
|
||||||
|
|
||||||
|
|||||||
@@ -2355,6 +2355,21 @@ class AppLocalizationsJa extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'ブックマークを削除';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'メッセージを選択';
|
String get chat_selectMessages => 'メッセージを選択';
|
||||||
|
|
||||||
|
|||||||
@@ -2357,6 +2357,21 @@ class AppLocalizationsKo extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => '북마크 삭제';
|
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
|
@override
|
||||||
String get chat_selectMessages => '메시지 선택';
|
String get chat_selectMessages => '메시지 선택';
|
||||||
|
|
||||||
|
|||||||
@@ -2455,6 +2455,21 @@ class AppLocalizationsNl extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Bladwijzer verwijderen';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Berichten selecteren';
|
String get chat_selectMessages => 'Berichten selecteren';
|
||||||
|
|
||||||
|
|||||||
@@ -2488,6 +2488,21 @@ class AppLocalizationsPl extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Usuń zakładkę';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Wybierz wiadomości';
|
String get chat_selectMessages => 'Wybierz wiadomości';
|
||||||
|
|
||||||
|
|||||||
@@ -2466,6 +2466,21 @@ class AppLocalizationsPt extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Remover marcador';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Selecionar mensagens';
|
String get chat_selectMessages => 'Selecionar mensagens';
|
||||||
|
|
||||||
|
|||||||
@@ -2469,6 +2469,21 @@ class AppLocalizationsRu extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Убрать из закладок';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Выбрать сообщения';
|
String get chat_selectMessages => 'Выбрать сообщения';
|
||||||
|
|
||||||
|
|||||||
@@ -2461,6 +2461,21 @@ class AppLocalizationsSk extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Odstrániť záložku';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Vybrať správy';
|
String get chat_selectMessages => 'Vybrať správy';
|
||||||
|
|
||||||
|
|||||||
@@ -2462,6 +2462,21 @@ class AppLocalizationsSl extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Odstrani zaznamek';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Izberi sporočila';
|
String get chat_selectMessages => 'Izberi sporočila';
|
||||||
|
|
||||||
|
|||||||
@@ -2444,6 +2444,21 @@ class AppLocalizationsSv extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Ta bort bokmärke';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Markera meddelanden';
|
String get chat_selectMessages => 'Markera meddelanden';
|
||||||
|
|
||||||
|
|||||||
@@ -2466,6 +2466,21 @@ class AppLocalizationsUk extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => 'Прибрати із закладок';
|
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
|
@override
|
||||||
String get chat_selectMessages => 'Вибрати повідомлення';
|
String get chat_selectMessages => 'Вибрати повідомлення';
|
||||||
|
|
||||||
|
|||||||
@@ -2325,6 +2325,21 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get bookmarks_remove => '移除书签';
|
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
|
@override
|
||||||
String get chat_selectMessages => '选择消息';
|
String get chat_selectMessages => '选择消息';
|
||||||
|
|
||||||
|
|||||||
+578
-135
@@ -1,17 +1,38 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../connector/meshcore_connector.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/message_url_image_helper.dart';
|
||||||
|
import '../helpers/snack_bar_builder.dart';
|
||||||
import '../l10n/l10n.dart';
|
import '../l10n/l10n.dart';
|
||||||
import '../models/bookmarked_message.dart';
|
import '../models/bookmarked_message.dart';
|
||||||
import '../services/app_settings_service.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/chat_send_pipeline.dart';
|
||||||
import '../widgets/empty_state.dart';
|
import '../widgets/empty_state.dart';
|
||||||
|
import '../widgets/mesh_ui.dart';
|
||||||
import '../widgets/translated_message_content.dart';
|
import '../widgets/translated_message_content.dart';
|
||||||
|
|
||||||
class BookmarksScreen extends StatefulWidget {
|
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
|
@override
|
||||||
State<BookmarksScreen> createState() => _BookmarksScreenState();
|
State<BookmarksScreen> createState() => _BookmarksScreenState();
|
||||||
@@ -19,168 +40,590 @@ class BookmarksScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _BookmarksScreenState extends State<BookmarksScreen> {
|
class _BookmarksScreenState extends State<BookmarksScreen> {
|
||||||
late Future<List<BookmarkedMessage>> _bookmarks;
|
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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.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() {
|
void _reload() {
|
||||||
setState(() {
|
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 {
|
Future<void> _remove(BookmarkedMessage bookmark) async {
|
||||||
|
final confirmed = await confirmRemoveBookmarks(context);
|
||||||
|
if (!confirmed || !mounted) return;
|
||||||
await context.read<MeshCoreConnector>().setBookmarkedMessage(
|
await context.read<MeshCoreConnector>().setBookmarkedMessage(
|
||||||
bookmark,
|
bookmark,
|
||||||
isBookmarked: false,
|
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();
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final l10n = context.l10n;
|
final l10n = context.l10n;
|
||||||
final publicIpfsGateway = context
|
final publicIpfsGateway =
|
||||||
.watch<AppSettingsService>()
|
context.watch<AppSettingsService?>()?.settings.publicIpfsGateway ?? '';
|
||||||
.settings
|
final textScale = context.watch<ChatTextScaleService?>()?.scale ?? 1.0;
|
||||||
.publicIpfsGateway;
|
|
||||||
return Scaffold(
|
return PopScope(
|
||||||
appBar: AppBar(title: Text(l10n.bookmarks_title), centerTitle: true),
|
canPop: !_searching && !_selecting,
|
||||||
body: FutureBuilder<List<BookmarkedMessage>>(
|
onPopInvokedWithResult: (didPop, _) {
|
||||||
future: _bookmarks,
|
if (didPop) return;
|
||||||
builder: (context, snapshot) {
|
if (_selecting) {
|
||||||
if (snapshot.connectionState != ConnectionState.done) {
|
_clearSelection();
|
||||||
return const Center(child: CircularProgressIndicator());
|
} else if (_searching) {
|
||||||
}
|
_closeSearch();
|
||||||
final bookmarks = snapshot.data ?? const <BookmarkedMessage>[];
|
}
|
||||||
if (bookmarks.isEmpty) {
|
},
|
||||||
return EmptyState(
|
child: Scaffold(
|
||||||
icon: Icons.bookmark_border,
|
appBar: _selecting
|
||||||
title: l10n.bookmarks_empty,
|
? _buildSelectionAppBar(context)
|
||||||
);
|
: AppBar(
|
||||||
}
|
leading: _searching
|
||||||
bookmarks.sort((a, b) => a.receivedAt.compareTo(b.receivedAt));
|
? IconButton(
|
||||||
return ListView.builder(
|
tooltip: l10n.chatSearch_close,
|
||||||
reverse: true,
|
icon: const Icon(Icons.arrow_back),
|
||||||
padding: const EdgeInsets.all(12),
|
onPressed: _closeSearch,
|
||||||
itemCount: bookmarks.length,
|
)
|
||||||
itemBuilder: (context, index) {
|
: null,
|
||||||
final bookmark = bookmarks[bookmarks.length - 1 - index];
|
title: _searching
|
||||||
final sourceType =
|
? _buildSearchField()
|
||||||
bookmark.sourceType == BookmarkSourceType.channel
|
: Text(l10n.bookmarks_title),
|
||||||
? l10n.bookmarks_channel
|
centerTitle: !_searching,
|
||||||
: l10n.bookmarks_contact;
|
actions: _searching
|
||||||
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
|
? null
|
||||||
: bookmark.text,
|
: [
|
||||||
style: textStyle,
|
IconButton(
|
||||||
originalStyle: textStyle.copyWith(fontStyle: FontStyle.italic),
|
tooltip: l10n.chatSearch_tooltip,
|
||||||
backgroundColor:
|
icon: const Icon(Icons.search),
|
||||||
Theme.of(context).cardTheme.color ??
|
onPressed: _openSearch,
|
||||||
Theme.of(context).colorScheme.surfaceContainerLow,
|
),
|
||||||
);
|
],
|
||||||
return Card(
|
),
|
||||||
margin: const EdgeInsets.only(bottom: 10),
|
body: Column(
|
||||||
child: Padding(
|
children: [
|
||||||
padding: const EdgeInsets.fromLTRB(16, 12, 8, 12),
|
if (_hasInitialSource) _buildScopePill(context),
|
||||||
child: Column(
|
Expanded(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
child: _showSearchResults
|
||||||
children: [
|
? ChatSearchResults(
|
||||||
Row(
|
key: ValueKey<bool>(_filterToInitialSource),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
query: _searchQuery.trim(),
|
||||||
children: [
|
loadEntries: _loadSearchEntries,
|
||||||
const Padding(
|
textScale: textScale,
|
||||||
padding: EdgeInsets.only(top: 2, right: 8),
|
onSelect: (entry) =>
|
||||||
child: Icon(
|
unawaited(_jumpToSearchResult(entry.id)),
|
||||||
Icons.bookmark,
|
)
|
||||||
size: 20,
|
: FutureBuilder<List<BookmarkedMessage>>(
|
||||||
color: Color(0xFFFFE54A),
|
future: _bookmarks,
|
||||||
),
|
builder: (context, snapshot) {
|
||||||
),
|
if (snapshot.connectionState != ConnectionState.done) {
|
||||||
Expanded(
|
return const Center(
|
||||||
child: Column(
|
child: CircularProgressIndicator(),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
);
|
||||||
children: [
|
}
|
||||||
Text(
|
final connector = context.watch<MeshCoreConnector>();
|
||||||
'$sourceType · ${bookmark.sourceName}',
|
final allBookmarks =
|
||||||
style: Theme.of(context).textTheme.titleSmall,
|
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),
|
onLongPress: _selecting
|
||||||
Text(
|
? null
|
||||||
'${bookmark.senderName} · $dateTime',
|
: () => _toggleSelected(bookmark),
|
||||||
style: Theme.of(context).textTheme.bodySmall,
|
child: Padding(
|
||||||
),
|
padding: const EdgeInsets.fromLTRB(
|
||||||
],
|
16,
|
||||||
),
|
12,
|
||||||
),
|
8,
|
||||||
IconButton(
|
12,
|
||||||
tooltip: l10n.common_copy,
|
),
|
||||||
onPressed: () =>
|
child: Column(
|
||||||
copyChatMessageText(context, bookmark.text),
|
crossAxisAlignment:
|
||||||
icon: const Icon(Icons.copy),
|
CrossAxisAlignment.start,
|
||||||
),
|
children: [
|
||||||
IconButton(
|
Row(
|
||||||
tooltip: l10n.bookmarks_remove,
|
crossAxisAlignment:
|
||||||
onPressed: () => _remove(bookmark),
|
CrossAxisAlignment.start,
|
||||||
icon: const Icon(Icons.bookmark_remove_outlined),
|
children: [
|
||||||
),
|
const Padding(
|
||||||
],
|
padding: EdgeInsets.only(
|
||||||
),
|
top: 2,
|
||||||
const SizedBox(height: 8),
|
right: 8,
|
||||||
if (MessageUrlImageHelper.hasPotentialImageUrl(
|
),
|
||||||
bookmark.text,
|
child: Icon(
|
||||||
))
|
Icons.bookmark,
|
||||||
MessageUrlImageFutureBuilder(
|
size: 20,
|
||||||
messageId: bookmark.messageId,
|
color: Color(0xFFFFE54A),
|
||||||
text: bookmark.text,
|
),
|
||||||
publicGateway: publicIpfsGateway,
|
),
|
||||||
builder: (context, snapshot) {
|
Expanded(
|
||||||
final imageUrl = snapshot.data;
|
child: Column(
|
||||||
if (imageUrl == null) return textContent;
|
crossAxisAlignment:
|
||||||
return Column(
|
CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Text(
|
||||||
Padding(
|
'$sourceType · ${bookmark.sourceName}',
|
||||||
padding: const EdgeInsets.only(bottom: 8),
|
style: Theme.of(
|
||||||
child: MessageUrlImagePreview(
|
context,
|
||||||
imageUrl: imageUrl,
|
).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,
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ import '../widgets/mesh_ui.dart';
|
|||||||
import '../widgets/share_contact_sheet.dart';
|
import '../widgets/share_contact_sheet.dart';
|
||||||
import '../widgets/shared_contact_card.dart';
|
import '../widgets/shared_contact_card.dart';
|
||||||
import 'app_settings_screen.dart';
|
import 'app_settings_screen.dart';
|
||||||
|
import 'bookmarks_screen.dart';
|
||||||
import 'channel_chat_transcript_grouping.dart';
|
import 'channel_chat_transcript_grouping.dart';
|
||||||
import 'channels_screen.dart' show confirmDeleteChannel, showEditChannelSheet;
|
import 'channels_screen.dart' show confirmDeleteChannel, showEditChannelSheet;
|
||||||
import 'channel_message_path_screen.dart';
|
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:
|
/// Message ids picked for a bulk action. Non-empty means selection mode:
|
||||||
/// taps toggle messages and the app bar shows the bulk actions.
|
/// taps toggle messages and the app bar shows the bulk actions.
|
||||||
final Set<String> _selectedIds = <String>{};
|
final Set<String> _selectedIds = <String>{};
|
||||||
bool _showBookmarkedOnly = false;
|
|
||||||
bool get _selecting => _selectedIds.isNotEmpty;
|
bool get _selecting => _selectedIds.isNotEmpty;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -609,10 +609,27 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
onSaved: _onChannelEdited,
|
onSaved: _onChannelEdited,
|
||||||
);
|
);
|
||||||
case 'showBookmarks':
|
case 'showBookmarks':
|
||||||
setState(() {
|
final channelLabel = widget.channel.name.isEmpty
|
||||||
_showBookmarkedOnly = !_showBookmarkedOnly;
|
? '#${context.l10n.channels_channelIndex(widget.channel.index)}'
|
||||||
_selectedIds.clear();
|
: (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':
|
case 'background':
|
||||||
showChatBackgroundSheet(
|
showChatBackgroundSheet(
|
||||||
context,
|
context,
|
||||||
@@ -671,9 +688,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 'showBookmarks',
|
value: 'showBookmarks',
|
||||||
child: _menuRow(
|
child: _menuRow(
|
||||||
_showBookmarkedOnly ? Icons.bookmark : Icons.bookmark_border,
|
Icons.bookmark_border,
|
||||||
context.l10n.chat_showBookmarks,
|
context.l10n.bookmarks_title,
|
||||||
color: _showBookmarkedOnly ? const Color(0xFFFFE54A) : null,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
@@ -908,22 +924,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
final layout = _transcriptLayoutFor(
|
final layout = _transcriptLayoutFor(
|
||||||
context,
|
context,
|
||||||
messages,
|
messages,
|
||||||
showBookmarkedOnly: _showBookmarkedOnly,
|
|
||||||
);
|
);
|
||||||
// Fewer entries than messages means the message filter
|
// Fewer entries than messages means the message filter
|
||||||
// hid or collapsed some; bookmark filtering is deliberate.
|
// hid or collapsed some.
|
||||||
final hidesMessages =
|
final hidesMessages = layout.length < messages.length;
|
||||||
!_showBookmarkedOnly &&
|
|
||||||
layout.length < messages.length;
|
|
||||||
if (hidesMessages) _scheduleHiddenHistoryBackfill();
|
if (hidesMessages) _scheduleHiddenHistoryBackfill();
|
||||||
|
|
||||||
if (layout.length == 0) {
|
if (layout.length == 0) {
|
||||||
if (_showBookmarkedOnly) {
|
|
||||||
return EmptyState(
|
|
||||||
icon: Icons.bookmark_border,
|
|
||||||
title: context.l10n.bookmarks_empty,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final canLoadOlder =
|
final canLoadOlder =
|
||||||
hidesMessages && !_olderHistoryExhausted;
|
hidesMessages && !_olderHistoryExhausted;
|
||||||
return EmptyState(
|
return EmptyState(
|
||||||
@@ -1243,7 +1250,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
: null,
|
: null,
|
||||||
child: MessageBubbleFrame(
|
child: MessageBubbleFrame(
|
||||||
isOutgoing: isOutgoing,
|
isOutgoing: isOutgoing,
|
||||||
isBookmarked: message.isBookmarked || _showBookmarkedOnly,
|
isBookmarked: message.isBookmarked,
|
||||||
compact: gifId != null,
|
compact: gifId != null,
|
||||||
maxWidth: constraints.maxWidth,
|
maxWidth: constraints.maxWidth,
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -2285,9 +2292,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
/// `State`'s) — `watch` asserts on that.
|
/// `State`'s) — `watch` asserts on that.
|
||||||
_TranscriptLayout _transcriptLayoutFor(
|
_TranscriptLayout _transcriptLayoutFor(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
List<ChannelMessage> messages, {
|
List<ChannelMessage> messages,
|
||||||
bool showBookmarkedOnly = false,
|
) {
|
||||||
}) {
|
|
||||||
ReceivedImageStore? store;
|
ReceivedImageStore? store;
|
||||||
try {
|
try {
|
||||||
store = context.watch<ReceivedImageStore>();
|
store = context.watch<ReceivedImageStore>();
|
||||||
@@ -2316,7 +2322,6 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
displayMode,
|
displayMode,
|
||||||
filterActive,
|
filterActive,
|
||||||
_revealVersion,
|
_revealVersion,
|
||||||
showBookmarkedOnly,
|
|
||||||
_filteredMessagesSignature(messages),
|
_filteredMessagesSignature(messages),
|
||||||
Object.hashAll(
|
Object.hashAll(
|
||||||
messages
|
messages
|
||||||
@@ -2325,8 +2330,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
final cached = _transcriptLayout;
|
final cached = _transcriptLayout;
|
||||||
if (!showBookmarkedOnly &&
|
if (cached != null &&
|
||||||
cached != null &&
|
|
||||||
cached.matches(
|
cached.matches(
|
||||||
messages,
|
messages,
|
||||||
_imageStoreVersion,
|
_imageStoreVersion,
|
||||||
@@ -2335,14 +2339,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
)) {
|
)) {
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
final displayedMessages = showBookmarkedOnly
|
final images = store == null
|
||||||
? messages.where((message) => message.isBookmarked).toList()
|
|
||||||
: messages;
|
|
||||||
final images = store == null || showBookmarkedOnly
|
|
||||||
? const <ReceivedImageEntry>[]
|
? const <ReceivedImageEntry>[]
|
||||||
: store.entriesForChannel(widget.channel.storageId);
|
: store.entriesForChannel(widget.channel.storageId);
|
||||||
final layout = _TranscriptLayout.build(
|
final layout = _TranscriptLayout.build(
|
||||||
messages: displayedMessages,
|
messages: messages,
|
||||||
images: images,
|
images: images,
|
||||||
imageVersion: _imageStoreVersion,
|
imageVersion: _imageStoreVersion,
|
||||||
channelIndex: widget.channel.index,
|
channelIndex: widget.channel.index,
|
||||||
@@ -3188,8 +3189,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
? context.l10n.chat_removeBookmark
|
? context.l10n.chat_removeBookmark
|
||||||
: context.l10n.chat_bookmark,
|
: context.l10n.chat_bookmark,
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
|
final connector = context.read<MeshCoreConnector>();
|
||||||
|
final selfLabel = connector.selfName ?? context.l10n.chat_me;
|
||||||
Navigator.pop(sheetContext);
|
Navigator.pop(sheetContext);
|
||||||
|
if (message.isBookmarked) {
|
||||||
|
final confirmed = await confirmRemoveBookmarks(context);
|
||||||
|
if (!confirmed || !mounted) return;
|
||||||
|
}
|
||||||
final bookmark = BookmarkedMessage.fromChannel(
|
final bookmark = BookmarkedMessage.fromChannel(
|
||||||
message: message,
|
message: message,
|
||||||
channelId:
|
channelId:
|
||||||
@@ -3197,15 +3204,12 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
'slot:${widget.channel.index}',
|
'slot:${widget.channel.index}',
|
||||||
channelName: widget.channel.name,
|
channelName: widget.channel.name,
|
||||||
senderName: message.isOutgoing
|
senderName: message.isOutgoing
|
||||||
? (context.read<MeshCoreConnector>().selfName ??
|
? selfLabel
|
||||||
context.l10n.chat_me)
|
|
||||||
: message.senderName,
|
: message.senderName,
|
||||||
);
|
);
|
||||||
unawaited(
|
await connector.setBookmarkedMessage(
|
||||||
context.read<MeshCoreConnector>().setBookmarkedMessage(
|
bookmark,
|
||||||
bookmark,
|
isBookmarked: !message.isBookmarked,
|
||||||
isBookmarked: !message.isBookmarked,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -3309,10 +3313,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
final filterActive = _transcriptLayout?.filterActive ?? true;
|
final filterActive = _transcriptLayout?.filterActive ?? true;
|
||||||
return [
|
return [
|
||||||
for (final m in messages)
|
for (final m in messages)
|
||||||
if ((!_showBookmarkedOnly || m.isBookmarked) &&
|
if (!(filterActive &&
|
||||||
!(filterActive &&
|
m.isFiltered &&
|
||||||
m.isFiltered &&
|
!_revealedFilteredIds.contains(m.messageId)))
|
||||||
!_revealedFilteredIds.contains(m.messageId)))
|
|
||||||
m,
|
m,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -3391,6 +3394,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
icon: const Icon(Icons.visibility_outlined),
|
icon: const Icon(Icons.visibility_outlined),
|
||||||
onPressed: () => _bulkMarkNotSpam(notSpamCandidates),
|
onPressed: () => _bulkMarkNotSpam(notSpamCandidates),
|
||||||
),
|
),
|
||||||
|
IconButton(
|
||||||
|
tooltip: l10n.chat_bookmark,
|
||||||
|
icon: const Icon(Icons.bookmark_add_outlined),
|
||||||
|
onPressed: selected.isEmpty ? null : () => _bulkBookmark(selected),
|
||||||
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: l10n.common_delete,
|
tooltip: l10n.common_delete,
|
||||||
icon: const Icon(Icons.delete_outline),
|
icon: const Icon(Icons.delete_outline),
|
||||||
@@ -3465,6 +3473,25 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
|||||||
showDismissibleSnackBar(context, content: Text(text));
|
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 {
|
Future<void> _bulkDelete(List<ChannelMessage> messages) async {
|
||||||
final connector = context.read<MeshCoreConnector>();
|
final connector = context.read<MeshCoreConnector>();
|
||||||
final confirmed = await confirmBulkDelete(context, messages.length);
|
final confirmed = await confirmBulkDelete(context, messages.length);
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import '../widgets/chat_zoom_wrapper.dart';
|
|||||||
import '../widgets/message_bubble_frame.dart';
|
import '../widgets/message_bubble_frame.dart';
|
||||||
import '../widgets/reaction_chips.dart';
|
import '../widgets/reaction_chips.dart';
|
||||||
import '../widgets/chat_day_separator.dart';
|
import '../widgets/chat_day_separator.dart';
|
||||||
|
import 'bookmarks_screen.dart';
|
||||||
import 'channel_message_path_screen.dart';
|
import 'channel_message_path_screen.dart';
|
||||||
import 'contacts_screen.dart' show confirmRemoveContact;
|
import 'contacts_screen.dart' show confirmRemoveContact;
|
||||||
import 'map_screen.dart';
|
import 'map_screen.dart';
|
||||||
@@ -97,13 +98,12 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
|||||||
final _textController = TextEditingController();
|
final _textController = TextEditingController();
|
||||||
final _scrollController = ChatScrollController();
|
final _scrollController = ChatScrollController();
|
||||||
final _scrollAnchor = ChatScrollAnchor();
|
final _scrollAnchor = ChatScrollAnchor();
|
||||||
({String id, bool bookmarksOnly})? _newestRow;
|
String? _newestRowId;
|
||||||
final _textFieldFocusNode = FocusNode();
|
final _textFieldFocusNode = FocusNode();
|
||||||
bool _focusLostWhileAway = false;
|
bool _focusLostWhileAway = false;
|
||||||
bool _focusLostToRoute = false;
|
bool _focusLostToRoute = false;
|
||||||
final GlobalKey _unreadScrollKey = GlobalKey();
|
final GlobalKey _unreadScrollKey = GlobalKey();
|
||||||
bool _isLoadingOlder = false;
|
bool _isLoadingOlder = false;
|
||||||
bool _showBookmarkedOnly = false;
|
|
||||||
MeshCoreConnector? _connector;
|
MeshCoreConnector? _connector;
|
||||||
Message? _pendingUnreadScrollTarget;
|
Message? _pendingUnreadScrollTarget;
|
||||||
String? _unreadDividerMessageId;
|
String? _unreadDividerMessageId;
|
||||||
@@ -513,8 +513,15 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
|||||||
case 'settings':
|
case 'settings':
|
||||||
_showContactSettings(context);
|
_showContactSettings(context);
|
||||||
case 'showBookmarks':
|
case 'showBookmarks':
|
||||||
setState(
|
Navigator.push(
|
||||||
() => _showBookmarkedOnly = !_showBookmarkedOnly,
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (_) => BookmarksScreen(
|
||||||
|
initialSourceType: BookmarkSourceType.contact,
|
||||||
|
initialSourceId: widget.contact.publicKeyHex,
|
||||||
|
initialSourceName: contact.name,
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
case 'background':
|
case 'background':
|
||||||
showChatBackgroundSheet(
|
showChatBackgroundSheet(
|
||||||
@@ -586,13 +593,8 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
|||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 'showBookmarks',
|
value: 'showBookmarks',
|
||||||
child: MeshMenuItemRow(
|
child: MeshMenuItemRow(
|
||||||
icon: _showBookmarkedOnly
|
icon: Icons.bookmark_border,
|
||||||
? Icons.bookmark
|
label: context.l10n.bookmarks_title,
|
||||||
: Icons.bookmark_border,
|
|
||||||
label: context.l10n.chat_showBookmarks,
|
|
||||||
color: _showBookmarkedOnly
|
|
||||||
? const Color(0xFFFFE54A)
|
|
||||||
: null,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
@@ -697,7 +699,6 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEmptyState() {
|
Widget _buildEmptyState() {
|
||||||
if (_showBookmarkedOnly) return _buildBookmarkEmptyState();
|
|
||||||
return EmptyState(
|
return EmptyState(
|
||||||
icon: Icons.chat_bubble_outline,
|
icon: Icons.chat_bubble_outline,
|
||||||
title: context.l10n.chat_noMessages,
|
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(
|
Widget _buildMessageList(
|
||||||
List<Message> messages,
|
List<Message> messages,
|
||||||
MeshCoreConnector connector,
|
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
|
// 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);
|
final itemCount = reversedMessages.length + (_isLoadingOlder ? 1 : 0);
|
||||||
|
|
||||||
// A reader scrolled up keeps their place when messages arrive below, as
|
// A reader scrolled up keeps their place when messages arrive below, as
|
||||||
// a room's backlog does in a burst right after login.
|
// a room's backlog does in a burst right after login.
|
||||||
final previous = _newestRow;
|
final previousId = _newestRowId;
|
||||||
final newest = (
|
final newestId = reversedMessages.first.messageId;
|
||||||
id: reversedMessages.first.messageId,
|
_newestRowId = newestId;
|
||||||
bookmarksOnly: _showBookmarkedOnly,
|
if (previousId != null &&
|
||||||
);
|
previousId != newestId &&
|
||||||
_newestRow = newest;
|
|
||||||
if (previous != null &&
|
|
||||||
previous.bookmarksOnly == newest.bookmarksOnly &&
|
|
||||||
previous.id != newest.id &&
|
|
||||||
_pendingUnreadScrollTarget == null &&
|
_pendingUnreadScrollTarget == null &&
|
||||||
_scrollController.showJumpToBottom.value) {
|
_scrollController.showJumpToBottom.value) {
|
||||||
final inserted = reversedMessages.indexWhere(
|
final inserted = reversedMessages.indexWhere(
|
||||||
(m) => m.messageId == previous.id,
|
(m) => m.messageId == previousId,
|
||||||
);
|
);
|
||||||
if (inserted > 0) _scrollAnchor.rowsInsertedBelow(inserted);
|
if (inserted > 0) _scrollAnchor.rowsInsertedBelow(inserted);
|
||||||
}
|
}
|
||||||
@@ -825,7 +811,7 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
|||||||
: contact.name,
|
: contact.name,
|
||||||
sourceId: widget.contact.publicKeyHex,
|
sourceId: widget.contact.publicKeyHex,
|
||||||
textScale: textScale,
|
textScale: textScale,
|
||||||
isBookmarked: message.isBookmarked || _showBookmarkedOnly,
|
isBookmarked: message.isBookmarked,
|
||||||
onLongPress: () => _showMessageActions(message, contact),
|
onLongPress: () => _showMessageActions(message, contact),
|
||||||
onRetryReaction: (msg, emoji) =>
|
onRetryReaction: (msg, emoji) =>
|
||||||
_sendReaction(msg, contact, emoji),
|
_sendReaction(msg, contact, emoji),
|
||||||
@@ -1488,22 +1474,23 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
|||||||
? context.l10n.chat_removeBookmark
|
? context.l10n.chat_removeBookmark
|
||||||
: context.l10n.chat_bookmark,
|
: context.l10n.chat_bookmark,
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
|
final connector = context.read<MeshCoreConnector>();
|
||||||
|
final selfLabel = connector.selfName ?? context.l10n.chat_me;
|
||||||
Navigator.pop(sheetContext);
|
Navigator.pop(sheetContext);
|
||||||
|
if (message.isBookmarked) {
|
||||||
|
final confirmed = await confirmRemoveBookmarks(context);
|
||||||
|
if (!confirmed || !mounted) return;
|
||||||
|
}
|
||||||
final bookmark = BookmarkedMessage.fromContact(
|
final bookmark = BookmarkedMessage.fromContact(
|
||||||
message: message,
|
message: message,
|
||||||
contactKey: widget.contact.publicKeyHex,
|
contactKey: widget.contact.publicKeyHex,
|
||||||
contactName: widget.contact.name,
|
contactName: widget.contact.name,
|
||||||
senderName: message.isOutgoing
|
senderName: message.isOutgoing ? selfLabel : contact.name,
|
||||||
? (context.read<MeshCoreConnector>().selfName ??
|
|
||||||
context.l10n.chat_me)
|
|
||||||
: contact.name,
|
|
||||||
);
|
);
|
||||||
unawaited(
|
await connector.setBookmarkedMessage(
|
||||||
context.read<MeshCoreConnector>().setBookmarkedMessage(
|
bookmark,
|
||||||
bookmark,
|
isBookmarked: !message.isBookmarked,
|
||||||
isBookmarked: !message.isBookmarked,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import '../widgets/sync_progress_overlay.dart';
|
|||||||
import '../widgets/unread_badge.dart';
|
import '../widgets/unread_badge.dart';
|
||||||
import '../helpers/snack_bar_builder.dart';
|
import '../helpers/snack_bar_builder.dart';
|
||||||
import 'add_contact_screen.dart';
|
import 'add_contact_screen.dart';
|
||||||
|
import 'bookmarks_screen.dart';
|
||||||
import 'channels_screen.dart';
|
import 'channels_screen.dart';
|
||||||
import 'chat_screen.dart';
|
import 'chat_screen.dart';
|
||||||
import 'discovery_screen.dart';
|
import 'discovery_screen.dart';
|
||||||
@@ -384,6 +385,16 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
|||||||
MaterialPageRoute(builder: (_) => const DiscoveryScreen()),
|
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(),
|
const PopupMenuDivider(),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
enabled: !readOnly,
|
enabled: !readOnly,
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ class BookmarkStore {
|
|||||||
|
|
||||||
String get keyFor => '$_keyPrefix$publicKeyHex';
|
String get keyFor => '$_keyPrefix$publicKeyHex';
|
||||||
|
|
||||||
Future<void> _pendingWrites = Future<void>.value();
|
Future<void>? _pendingWrites;
|
||||||
|
|
||||||
Future<List<BookmarkedMessage>> loadBookmarks() async {
|
Future<List<BookmarkedMessage>> loadBookmarks() async {
|
||||||
final writes = _pendingWrites;
|
final writes = _pendingWrites;
|
||||||
await writes;
|
if (writes != null) await writes;
|
||||||
return _readBookmarks(keyFor);
|
return _readBookmarks(keyFor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,11 +47,20 @@ class BookmarkStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _enqueue(Future<void> Function() operation) {
|
Future<void> _enqueue(Future<void> Function() operation) {
|
||||||
final next = _pendingWrites.then((_) => operation());
|
final previous = _pendingWrites;
|
||||||
_pendingWrites = next.then<void>(
|
final next = previous == null
|
||||||
|
? Future<void>.sync(operation)
|
||||||
|
: previous.then((_) => operation());
|
||||||
|
final completion = next.then<void>(
|
||||||
(_) {},
|
(_) {},
|
||||||
onError: (Object _, StackTrace _) {},
|
onError: (Object _, StackTrace _) {},
|
||||||
);
|
);
|
||||||
|
_pendingWrites = completion;
|
||||||
|
completion.whenComplete(() {
|
||||||
|
if (identical(_pendingWrites, completion)) {
|
||||||
|
_pendingWrites = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -219,3 +219,42 @@ Future<bool> confirmClearChat(
|
|||||||
);
|
);
|
||||||
return confirmed == true;
|
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 Color? backgroundColor;
|
||||||
final bool showOriginalFirst;
|
final bool showOriginalFirst;
|
||||||
final VoidCallback? onSecondaryTap;
|
final VoidCallback? onSecondaryTap;
|
||||||
|
final bool selectable;
|
||||||
|
|
||||||
const TranslatedMessageContent({
|
const TranslatedMessageContent({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -20,6 +21,7 @@ class TranslatedMessageContent extends StatelessWidget {
|
|||||||
this.backgroundColor,
|
this.backgroundColor,
|
||||||
this.showOriginalFirst = true,
|
this.showOriginalFirst = true,
|
||||||
this.onSecondaryTap,
|
this.onSecondaryTap,
|
||||||
|
this.selectable = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -42,6 +44,7 @@ class TranslatedMessageContent extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
onSecondaryTap: onSecondaryTap,
|
onSecondaryTap: onSecondaryTap,
|
||||||
|
selectable: selectable,
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
final translatedWidget = LinkHandler.buildLinkifyText(
|
final translatedWidget = LinkHandler.buildLinkifyText(
|
||||||
@@ -50,6 +53,7 @@ class TranslatedMessageContent extends StatelessWidget {
|
|||||||
style: style,
|
style: style,
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
onSecondaryTap: onSecondaryTap,
|
onSecondaryTap: onSecondaryTap,
|
||||||
|
selectable: selectable,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!shouldShowOriginal) {
|
if (!shouldShowOriginal) {
|
||||||
|
|||||||
@@ -0,0 +1,741 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||||
|
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||||
|
import 'package:meshcore_open/models/bookmarked_message.dart';
|
||||||
|
import 'package:meshcore_open/review_mode/review_radio.dart';
|
||||||
|
import 'package:meshcore_open/screens/bookmarks_screen.dart';
|
||||||
|
import 'package:meshcore_open/screens/channel_chat_screen.dart';
|
||||||
|
import 'package:meshcore_open/screens/chat_screen.dart';
|
||||||
|
import 'package:meshcore_open/screens/contacts_screen.dart';
|
||||||
|
import 'package:meshcore_open/services/app_debug_log_service.dart';
|
||||||
|
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||||
|
import 'package:meshcore_open/services/ble_debug_log_service.dart';
|
||||||
|
import 'package:meshcore_open/services/chat_text_scale_service.dart';
|
||||||
|
import 'package:meshcore_open/services/image_codec_service.dart';
|
||||||
|
import 'package:meshcore_open/services/map_tile_cache_service.dart';
|
||||||
|
import 'package:meshcore_open/services/message_retry_service.dart';
|
||||||
|
import 'package:meshcore_open/services/network_map/network_map_upload_service.dart';
|
||||||
|
import 'package:meshcore_open/services/path_history_service.dart';
|
||||||
|
import 'package:meshcore_open/services/received_image_store.dart';
|
||||||
|
import 'package:meshcore_open/services/storage_service.dart';
|
||||||
|
import 'package:meshcore_open/services/timeout_prediction_service.dart';
|
||||||
|
import 'package:meshcore_open/services/translation_service.dart';
|
||||||
|
import 'package:meshcore_open/services/ui_view_state_service.dart';
|
||||||
|
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||||
|
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||||
|
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
||||||
|
import 'package:meshcore_open/widgets/message_bubble_frame.dart';
|
||||||
|
|
||||||
|
final _l10n = lookupAppLocalizations(const Locale('en'));
|
||||||
|
|
||||||
|
class _TestEnv {
|
||||||
|
final MeshCoreConnector connector;
|
||||||
|
final Widget Function(Widget home, {double textScale}) wrap;
|
||||||
|
|
||||||
|
_TestEnv({required this.connector, required this.wrap});
|
||||||
|
}
|
||||||
|
|
||||||
|
_TestEnv? _sharedEnv;
|
||||||
|
|
||||||
|
Future<T> _pumpFuture<T>(WidgetTester tester, Future<T> future) async {
|
||||||
|
var done = false;
|
||||||
|
late T result;
|
||||||
|
Object? error;
|
||||||
|
StackTrace? stack;
|
||||||
|
future.then(
|
||||||
|
(value) {
|
||||||
|
result = value;
|
||||||
|
done = true;
|
||||||
|
},
|
||||||
|
onError: (Object e, StackTrace s) {
|
||||||
|
error = e;
|
||||||
|
stack = s;
|
||||||
|
done = true;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
for (var i = 0; i < 50 && !done; i++) {
|
||||||
|
await tester.pump(const Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
if (!done) {
|
||||||
|
throw StateError('Timed out pumping future in FakeAsync');
|
||||||
|
}
|
||||||
|
if (error != null) Error.throwWithStackTrace(error!, stack!);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<_TestEnv> _createEnv(WidgetTester tester) async {
|
||||||
|
if (_sharedEnv != null) {
|
||||||
|
final existing = _sharedEnv!;
|
||||||
|
final bookmarks = await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
existing.connector.loadBookmarkedMessages(),
|
||||||
|
);
|
||||||
|
for (final bookmark in bookmarks) {
|
||||||
|
await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
existing.connector.setBookmarkedMessage(bookmark, isBookmarked: false),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (final channel in existing.connector.channels) {
|
||||||
|
for (final msg in existing.connector.getChannelMessages(channel)) {
|
||||||
|
if (msg.isBookmarked) {
|
||||||
|
await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
existing.connector.setBookmarkedMessage(
|
||||||
|
BookmarkedMessage.fromChannel(
|
||||||
|
message: msg,
|
||||||
|
channelId: channel.storageId ?? 'slot:${channel.index}',
|
||||||
|
channelName: channel.name,
|
||||||
|
senderName: msg.senderName,
|
||||||
|
),
|
||||||
|
isBookmarked: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
late final StorageService storage;
|
||||||
|
late final MeshCoreConnector connector;
|
||||||
|
late final MessageRetryService retry;
|
||||||
|
late final AppSettingsService settings;
|
||||||
|
late final TranslationService translation;
|
||||||
|
late final UiViewStateService viewState;
|
||||||
|
|
||||||
|
await tester.runAsync(() async {
|
||||||
|
storage = StorageService();
|
||||||
|
connector = MeshCoreConnector();
|
||||||
|
retry = MessageRetryService();
|
||||||
|
settings = AppSettingsService();
|
||||||
|
translation = TranslationService(settings);
|
||||||
|
viewState = UiViewStateService();
|
||||||
|
await settings.loadSettings();
|
||||||
|
connector.initialize(
|
||||||
|
retryService: retry,
|
||||||
|
pathHistoryService: PathHistoryService(storage),
|
||||||
|
appSettingsService: settings,
|
||||||
|
translationService: translation,
|
||||||
|
);
|
||||||
|
connector.reviewRadioFactoryForTest = () => ReviewRadio(
|
||||||
|
scheduledMessageInterval: const Duration(hours: 1),
|
||||||
|
ackDelay: const Duration(hours: 1),
|
||||||
|
replyDelay: const Duration(hours: 1),
|
||||||
|
);
|
||||||
|
await connector.connectReview();
|
||||||
|
final end = DateTime.now().add(const Duration(seconds: 8));
|
||||||
|
while ((connector.contacts.isEmpty ||
|
||||||
|
connector.channels.isEmpty ||
|
||||||
|
!connector.channelMapConfirmed) &&
|
||||||
|
DateTime.now().isBefore(end)) {
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 25));
|
||||||
|
}
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||||
|
});
|
||||||
|
|
||||||
|
final providers = [
|
||||||
|
ChangeNotifierProvider.value(value: connector),
|
||||||
|
ChangeNotifierProvider.value(value: retry),
|
||||||
|
ChangeNotifierProvider.value(value: PathHistoryService(storage)),
|
||||||
|
ChangeNotifierProvider.value(value: settings),
|
||||||
|
ChangeNotifierProvider.value(value: BleDebugLogService()),
|
||||||
|
ChangeNotifierProvider.value(value: AppDebugLogService()),
|
||||||
|
ChangeNotifierProvider.value(value: ChatTextScaleService()),
|
||||||
|
ChangeNotifierProvider.value(value: translation),
|
||||||
|
ChangeNotifierProvider.value(value: viewState),
|
||||||
|
Provider.value(value: storage),
|
||||||
|
ChangeNotifierProvider.value(
|
||||||
|
value: MapTileCacheService(appSettingsService: settings),
|
||||||
|
),
|
||||||
|
ChangeNotifierProvider.value(value: TimeoutPredictionService(storage)),
|
||||||
|
ChangeNotifierProvider.value(value: ImageCodecService(settings)),
|
||||||
|
ChangeNotifierProvider.value(value: ReceivedImageStore()),
|
||||||
|
ChangeNotifierProvider.value(
|
||||||
|
value: NetworkMapUploadService(connector: connector, settings: settings),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
Widget wrap(Widget home, {double textScale = 1.0}) {
|
||||||
|
return MultiProvider(
|
||||||
|
providers: providers,
|
||||||
|
child: MaterialApp(
|
||||||
|
key: UniqueKey(),
|
||||||
|
theme: MeshTheme.light(),
|
||||||
|
locale: const Locale('en'),
|
||||||
|
localizationsDelegates: const [
|
||||||
|
AppLocalizations.delegate,
|
||||||
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
GlobalCupertinoLocalizations.delegate,
|
||||||
|
],
|
||||||
|
supportedLocales: AppLocalizations.supportedLocales,
|
||||||
|
builder: (context, child) => MediaQuery(
|
||||||
|
data: MediaQuery.of(
|
||||||
|
context,
|
||||||
|
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||||
|
child: child!,
|
||||||
|
),
|
||||||
|
home: home,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _sharedEnv = _TestEnv(connector: connector, wrap: wrap);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _pumpFrames(WidgetTester tester, [int count = 8]) async {
|
||||||
|
for (var i = 0; i < count; i++) {
|
||||||
|
await tester.pump(const Duration(milliseconds: 100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Finder _segmentByText(String label) =>
|
||||||
|
find.byWidgetPredicate((w) => w is MeshSegmentLabel && w.text == label);
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
final tempDir = Directory.systemTemp.createTempSync('bookmarks_screen_test');
|
||||||
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||||
|
.setMockMethodCallHandler(
|
||||||
|
const MethodChannel('plugins.flutter.io/path_provider'),
|
||||||
|
(call) async => tempDir.path,
|
||||||
|
);
|
||||||
|
|
||||||
|
setUpAll(() async {
|
||||||
|
SharedPreferences.setMockInitialValues({});
|
||||||
|
PrefsManager.reset();
|
||||||
|
await PrefsManager.initialize();
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'Contacts overflow menu includes Bookmarks after Discovered Contacts and opens BookmarksScreen',
|
||||||
|
(tester) async {
|
||||||
|
final env = await _createEnv(tester);
|
||||||
|
await tester.pumpWidget(env.wrap(const ContactsScreen()));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.more_vert));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.text(_l10n.discoveredContacts_Title), findsOneWidget);
|
||||||
|
expect(find.text(_l10n.bookmarks_title), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.text(_l10n.bookmarks_title));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.byType(BookmarksScreen), findsOneWidget);
|
||||||
|
// No split pill when opened from main Contacts screen.
|
||||||
|
expect(find.byType(SegmentedButton<bool>), findsNothing);
|
||||||
|
|
||||||
|
await tester.pumpWidget(const SizedBox());
|
||||||
|
await tester.pump(const Duration(minutes: 1));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'ChannelChatScreen and ChatScreen overflow menus open BookmarksScreen with split pill filter',
|
||||||
|
(tester) async {
|
||||||
|
final env = await _createEnv(tester);
|
||||||
|
final channel = env.connector.channels.firstWhere(
|
||||||
|
(c) => c.name == 'Public',
|
||||||
|
);
|
||||||
|
final contact = env.connector.contacts.firstWhere(
|
||||||
|
(c) => c.name == 'Maya',
|
||||||
|
);
|
||||||
|
|
||||||
|
final channelBookmark = BookmarkedMessage(
|
||||||
|
sourceType: BookmarkSourceType.channel,
|
||||||
|
sourceId: channel.storageId ?? 'slot:${channel.index}',
|
||||||
|
sourceName: channel.name,
|
||||||
|
messageId: 'ch-msg-1',
|
||||||
|
senderName: 'Maya',
|
||||||
|
text: 'Public channel bookmarked note',
|
||||||
|
timestamp: DateTime(2026, 1, 1, 10),
|
||||||
|
receivedAt: DateTime(2026, 1, 1, 10),
|
||||||
|
isOutgoing: false,
|
||||||
|
);
|
||||||
|
final contactBookmark = BookmarkedMessage(
|
||||||
|
sourceType: BookmarkSourceType.contact,
|
||||||
|
sourceId: contact.publicKeyHex,
|
||||||
|
sourceName: contact.name,
|
||||||
|
messageId: 'dm-msg-1',
|
||||||
|
senderName: contact.name,
|
||||||
|
text: 'Direct message bookmarked note',
|
||||||
|
timestamp: DateTime(2026, 1, 1, 11),
|
||||||
|
receivedAt: DateTime(2026, 1, 1, 11),
|
||||||
|
isOutgoing: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
env.connector.setBookmarkedMessage(channelBookmark, isBookmarked: true),
|
||||||
|
);
|
||||||
|
await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
env.connector.setBookmarkedMessage(contactBookmark, isBookmarked: true),
|
||||||
|
);
|
||||||
|
|
||||||
|
// 1. Open from ChannelChatScreen
|
||||||
|
await tester.pumpWidget(env.wrap(ChannelChatScreen(channel: channel)));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.more_vert));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
expect(find.text(_l10n.bookmarks_title), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.text(_l10n.bookmarks_title));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.byType(BookmarksScreen), findsOneWidget);
|
||||||
|
expect(find.byType(SegmentedButton<bool>), findsOneWidget);
|
||||||
|
expect(_segmentByText(_l10n.listFilter_all), findsOneWidget);
|
||||||
|
expect(_segmentByText('#Public'), findsOneWidget);
|
||||||
|
|
||||||
|
// Defaults to current channel's bookmarks only.
|
||||||
|
expect(find.text('Public channel bookmarked note'), findsOneWidget);
|
||||||
|
expect(find.text('Direct message bookmarked note'), findsNothing);
|
||||||
|
|
||||||
|
// Tap "All" segment to view all bookmarks across the app.
|
||||||
|
await tester.tap(_segmentByText(_l10n.listFilter_all));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.text('Public channel bookmarked note'), findsOneWidget);
|
||||||
|
expect(find.text('Direct message bookmarked note'), findsOneWidget);
|
||||||
|
|
||||||
|
// Tap "#Public" segment to scope back to channel.
|
||||||
|
await tester.tap(_segmentByText('#Public'));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.text('Public channel bookmarked note'), findsOneWidget);
|
||||||
|
expect(find.text('Direct message bookmarked note'), findsNothing);
|
||||||
|
|
||||||
|
// 2. Open from ChatScreen (contact DM)
|
||||||
|
await tester.pumpWidget(env.wrap(ChatScreen(contact: contact)));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.more_vert));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
expect(find.text(_l10n.bookmarks_title), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.text(_l10n.bookmarks_title));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.byType(BookmarksScreen), findsOneWidget);
|
||||||
|
expect(_segmentByText(_l10n.listFilter_all), findsOneWidget);
|
||||||
|
expect(_segmentByText('Maya'), findsOneWidget);
|
||||||
|
expect(find.text('Direct message bookmarked note'), findsOneWidget);
|
||||||
|
expect(find.text('Public channel bookmarked note'), findsNothing);
|
||||||
|
|
||||||
|
await tester.pumpWidget(const SizedBox());
|
||||||
|
await tester.pump(const Duration(minutes: 1));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'Search in BookmarksScreen finds matching bookmarks and jumping highlights target card',
|
||||||
|
(tester) async {
|
||||||
|
final env = await _createEnv(tester);
|
||||||
|
final b1 = BookmarkedMessage(
|
||||||
|
sourceType: BookmarkSourceType.channel,
|
||||||
|
sourceId: 'slot:0',
|
||||||
|
sourceName: 'Public',
|
||||||
|
messageId: 'm1',
|
||||||
|
senderName: 'Sam',
|
||||||
|
text: 'Alpha repeater check on ridge',
|
||||||
|
timestamp: DateTime(2026, 1, 1, 9),
|
||||||
|
receivedAt: DateTime(2026, 1, 1, 9),
|
||||||
|
isOutgoing: false,
|
||||||
|
);
|
||||||
|
final b2 = BookmarkedMessage(
|
||||||
|
sourceType: BookmarkSourceType.contact,
|
||||||
|
sourceId: 'contact-1',
|
||||||
|
sourceName: 'Maya',
|
||||||
|
messageId: 'm2',
|
||||||
|
senderName: 'Maya',
|
||||||
|
text: 'Bravo solar battery voltage update',
|
||||||
|
timestamp: DateTime(2026, 1, 1, 10),
|
||||||
|
receivedAt: DateTime(2026, 1, 1, 10),
|
||||||
|
isOutgoing: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
env.connector.setBookmarkedMessage(b1, isBookmarked: true),
|
||||||
|
);
|
||||||
|
await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
env.connector.setBookmarkedMessage(b2, isBookmarked: true),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpWidget(env.wrap(const BookmarksScreen()));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.search));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
await tester.enterText(find.byType(TextField), 'solar');
|
||||||
|
await tester.pump(const Duration(milliseconds: 350));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
find.textContaining('Bravo solar battery voltage update'),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
expect(find.textContaining('Alpha repeater check'), findsNothing);
|
||||||
|
|
||||||
|
// Tap the search result to close search and highlight the card.
|
||||||
|
await tester.tap(
|
||||||
|
find.textContaining('Bravo solar battery voltage update'),
|
||||||
|
);
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
// Search field closed and AnimatedContainer highlight is active.
|
||||||
|
expect(find.byType(TextField), findsNothing);
|
||||||
|
expect(find.byType(AnimatedContainer), findsOneWidget);
|
||||||
|
|
||||||
|
// Highlight clears after 2 seconds.
|
||||||
|
await tester.pump(const Duration(seconds: 3));
|
||||||
|
expect(find.byType(AnimatedContainer), findsNothing);
|
||||||
|
|
||||||
|
await tester.pumpWidget(const SizedBox());
|
||||||
|
await tester.pump(const Duration(minutes: 1));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'Single removal and bulk removal in BookmarksScreen show confirmation AlertDialog',
|
||||||
|
(tester) async {
|
||||||
|
final env = await _createEnv(tester);
|
||||||
|
final b1 = BookmarkedMessage(
|
||||||
|
sourceType: BookmarkSourceType.channel,
|
||||||
|
sourceId: 'slot:0',
|
||||||
|
sourceName: 'Public',
|
||||||
|
messageId: 'm1',
|
||||||
|
senderName: 'Sam',
|
||||||
|
text: 'First bookmarked message',
|
||||||
|
timestamp: DateTime(2026, 1, 1, 9),
|
||||||
|
receivedAt: DateTime(2026, 1, 1, 9),
|
||||||
|
isOutgoing: false,
|
||||||
|
);
|
||||||
|
final b2 = BookmarkedMessage(
|
||||||
|
sourceType: BookmarkSourceType.channel,
|
||||||
|
sourceId: 'slot:0',
|
||||||
|
sourceName: 'Public',
|
||||||
|
messageId: 'm2',
|
||||||
|
senderName: 'Maya',
|
||||||
|
text: 'Second bookmarked message',
|
||||||
|
timestamp: DateTime(2026, 1, 1, 10),
|
||||||
|
receivedAt: DateTime(2026, 1, 1, 10),
|
||||||
|
isOutgoing: false,
|
||||||
|
);
|
||||||
|
final b3 = BookmarkedMessage(
|
||||||
|
sourceType: BookmarkSourceType.contact,
|
||||||
|
sourceId: 'contact-1',
|
||||||
|
sourceName: 'Maya',
|
||||||
|
messageId: 'm3',
|
||||||
|
senderName: 'Maya',
|
||||||
|
text: 'Third bookmarked message',
|
||||||
|
timestamp: DateTime(2026, 1, 1, 11),
|
||||||
|
receivedAt: DateTime(2026, 1, 1, 11),
|
||||||
|
isOutgoing: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
env.connector.setBookmarkedMessage(b1, isBookmarked: true),
|
||||||
|
);
|
||||||
|
await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
env.connector.setBookmarkedMessage(b2, isBookmarked: true),
|
||||||
|
);
|
||||||
|
await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
env.connector.setBookmarkedMessage(b3, isBookmarked: true),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpWidget(env.wrap(const BookmarksScreen()));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.text('Third bookmarked message'), findsOneWidget);
|
||||||
|
|
||||||
|
// 1. Single remove -> Cancel keeps bookmark intact.
|
||||||
|
await tester.tap(find.byIcon(Icons.bookmark_remove_outlined).first);
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.byType(AlertDialog), findsOneWidget);
|
||||||
|
expect(find.text(_l10n.bookmarks_removeConfirmTitle), findsOneWidget);
|
||||||
|
expect(find.text(_l10n.bookmarks_removeConfirmMessage), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.text(_l10n.common_cancel));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
expect(find.byType(AlertDialog), findsNothing);
|
||||||
|
expect(find.text('Third bookmarked message'), findsOneWidget);
|
||||||
|
|
||||||
|
// 2. Single remove -> Confirm removes bookmark.
|
||||||
|
await tester.tap(find.byIcon(Icons.bookmark_remove_outlined).first);
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
await tester.tap(find.text(_l10n.common_remove));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.text('Third bookmarked message'), findsNothing);
|
||||||
|
expect(find.text('Second bookmarked message'), findsOneWidget);
|
||||||
|
expect(find.text('First bookmarked message'), findsOneWidget);
|
||||||
|
|
||||||
|
// 3. Long-press to enter bulk selection mode and select both remaining bookmarks.
|
||||||
|
await tester.longPress(find.text('Second bookmarked message'));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.text(_l10n.chat_selectedCount(1)), findsOneWidget);
|
||||||
|
await tester.tap(
|
||||||
|
find.text('First bookmarked message'),
|
||||||
|
warnIfMissed: false,
|
||||||
|
);
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
expect(find.text(_l10n.chat_selectedCount(2)), findsOneWidget);
|
||||||
|
|
||||||
|
// Tap bulk delete icon -> Cancel keeps both bookmarks.
|
||||||
|
await tester.tap(find.byIcon(Icons.delete_outline));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.byType(AlertDialog), findsOneWidget);
|
||||||
|
expect(
|
||||||
|
find.text(_l10n.bookmarks_removeSelectedConfirmTitle),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
find.text(_l10n.bookmarks_removeSelectedConfirmMessage(2)),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.tap(find.text(_l10n.common_cancel));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
expect(find.text('Second bookmarked message'), findsOneWidget);
|
||||||
|
expect(find.text('First bookmarked message'), findsOneWidget);
|
||||||
|
|
||||||
|
// Tap bulk delete icon -> Confirm removes selected bookmarks.
|
||||||
|
await tester.tap(find.byIcon(Icons.delete_outline));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
await tester.tap(find.text(_l10n.common_remove));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(find.text(_l10n.bookmarks_empty), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.pumpWidget(const SizedBox());
|
||||||
|
await tester.pump(const Duration(minutes: 1));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'ChannelChatScreen bulk selection bookmarks selected messages and in-chat remove prompts for confirmation',
|
||||||
|
(tester) async {
|
||||||
|
final env = await _createEnv(tester);
|
||||||
|
final channel = env.connector.channels.firstWhere(
|
||||||
|
(c) => c.name == 'Hiking Group',
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpWidget(env.wrap(ChannelChatScreen(channel: channel)));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
final messages = env.connector.getChannelMessages(channel);
|
||||||
|
expect(messages.length, greaterThanOrEqualTo(2));
|
||||||
|
final firstMsg = messages[messages.length - 1];
|
||||||
|
final secondMsg = messages[messages.length - 2];
|
||||||
|
|
||||||
|
Future<void> longPressBubble(String text) async {
|
||||||
|
final bubble = find.ancestor(
|
||||||
|
of: find.text(text),
|
||||||
|
matching: find.byType(MessageBubbleFrame),
|
||||||
|
);
|
||||||
|
await tester.longPressAt(
|
||||||
|
tester.getTopLeft(bubble) + const Offset(8, 8),
|
||||||
|
);
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Long-press newest message to open action sheet -> Select messages
|
||||||
|
await longPressBubble(firstMsg.text);
|
||||||
|
|
||||||
|
await tester.tap(find.text(_l10n.chat_selectMessages));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
// Select second message too
|
||||||
|
await tester.tap(find.text(secondMsg.text), warnIfMissed: false);
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
expect(find.text(_l10n.chat_selectedCount(2)), findsOneWidget);
|
||||||
|
|
||||||
|
// Tap bulk Bookmark action in selection AppBar
|
||||||
|
final bookmarkBtn = find.byTooltip(_l10n.chat_bookmark);
|
||||||
|
expect(bookmarkBtn, findsOneWidget);
|
||||||
|
await tester.tap(bookmarkBtn);
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
final saved = await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
env.connector.loadBookmarkedMessages(),
|
||||||
|
);
|
||||||
|
expect(saved, hasLength(2));
|
||||||
|
|
||||||
|
// Now long-press the bookmarked message in ChannelChatScreen and tap "Remove bookmark"
|
||||||
|
await longPressBubble(firstMsg.text);
|
||||||
|
expect(find.text(_l10n.chat_removeBookmark), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.text(_l10n.chat_removeBookmark));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
// Confirmation dialog appears
|
||||||
|
expect(find.byType(AlertDialog), findsOneWidget);
|
||||||
|
expect(find.text(_l10n.bookmarks_removeConfirmTitle), findsOneWidget);
|
||||||
|
|
||||||
|
// Cancel keeps it bookmarked
|
||||||
|
await tester.tap(find.text(_l10n.common_cancel));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
expect(
|
||||||
|
await _pumpFuture(tester, env.connector.loadBookmarkedMessages()),
|
||||||
|
hasLength(2),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Confirm removes the bookmark
|
||||||
|
await longPressBubble(firstMsg.text);
|
||||||
|
await tester.tap(find.text(_l10n.chat_removeBookmark));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
await tester.tap(find.text(_l10n.common_remove));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await _pumpFuture(tester, env.connector.loadBookmarkedMessages()),
|
||||||
|
hasLength(1),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Also verify ChatScreen (direct message) bookmark removal confirmation dialog
|
||||||
|
final contact = env.connector.contacts.firstWhere(
|
||||||
|
(c) => c.name == 'Maya',
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(env.wrap(ChatScreen(contact: contact)));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
final dmMessages = env.connector.getMessages(contact);
|
||||||
|
expect(dmMessages, isNotEmpty);
|
||||||
|
final dmMsg = dmMessages.last;
|
||||||
|
|
||||||
|
// Bookmark the DM first
|
||||||
|
await longPressBubble(dmMsg.text);
|
||||||
|
await tester.tap(find.text(_l10n.chat_bookmark));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
expect(
|
||||||
|
await _pumpFuture(tester, env.connector.loadBookmarkedMessages()),
|
||||||
|
hasLength(2),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Long-press and tap Remove bookmark -> Cancel keeps it
|
||||||
|
await longPressBubble(dmMsg.text);
|
||||||
|
await tester.tap(find.text(_l10n.chat_removeBookmark));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
expect(find.byType(AlertDialog), findsOneWidget);
|
||||||
|
await tester.tap(find.text(_l10n.common_cancel));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
expect(
|
||||||
|
await _pumpFuture(tester, env.connector.loadBookmarkedMessages()),
|
||||||
|
hasLength(2),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Confirm removes it
|
||||||
|
await longPressBubble(dmMsg.text);
|
||||||
|
await tester.tap(find.text(_l10n.chat_removeBookmark));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
await tester.tap(find.text(_l10n.common_remove));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
expect(
|
||||||
|
await _pumpFuture(tester, env.connector.loadBookmarkedMessages()),
|
||||||
|
hasLength(1),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpWidget(const SizedBox());
|
||||||
|
await tester.pump(const Duration(minutes: 1));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
group('BookmarksScreen fits 320dp at 1.3x and 2.0x text scale', () {
|
||||||
|
for (final scale in [1.3, 2.0]) {
|
||||||
|
testWidgets('no layout overflow at 320dp and ${scale}x text scale', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
tester.view.physicalSize = const Size(320, 568);
|
||||||
|
tester.view.devicePixelRatio = 1.0;
|
||||||
|
addTearDown(tester.view.reset);
|
||||||
|
|
||||||
|
final env = await _createEnv(tester);
|
||||||
|
final channel = env.connector.channels.firstWhere(
|
||||||
|
(c) => c.name == 'Hiking Group',
|
||||||
|
);
|
||||||
|
await _pumpFuture(
|
||||||
|
tester,
|
||||||
|
env.connector.setBookmarkedMessage(
|
||||||
|
BookmarkedMessage(
|
||||||
|
sourceType: BookmarkSourceType.channel,
|
||||||
|
sourceId: channel.storageId ?? 'slot:${channel.index}',
|
||||||
|
sourceName: channel.name,
|
||||||
|
messageId: 'scale-msg-1',
|
||||||
|
senderName: 'Ranger Pat',
|
||||||
|
text:
|
||||||
|
'Checking layout on 320dp screen with large text scale enabled.',
|
||||||
|
timestamp: DateTime(2026, 1, 1, 12),
|
||||||
|
receivedAt: DateTime(2026, 1, 1, 12),
|
||||||
|
isOutgoing: false,
|
||||||
|
),
|
||||||
|
isBookmarked: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final overflows = <String>[];
|
||||||
|
final previous = FlutterError.onError;
|
||||||
|
FlutterError.onError = (details) {
|
||||||
|
final text = details.exceptionAsString();
|
||||||
|
if (!text.contains('overflowed')) {
|
||||||
|
previous?.call(details);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
overflows.add(text.split('\n').first);
|
||||||
|
};
|
||||||
|
addTearDown(() => FlutterError.onError = previous);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
env.wrap(
|
||||||
|
BookmarksScreen(
|
||||||
|
initialSourceType: BookmarkSourceType.channel,
|
||||||
|
initialSourceId: channel.storageId ?? 'slot:${channel.index}',
|
||||||
|
sourceIdAliases: [?channel.storageId, 'slot:${channel.index}'],
|
||||||
|
initialSourceName: '#${channel.name}',
|
||||||
|
),
|
||||||
|
textScale: scale,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
// Enter bulk selection mode and open remove confirmation dialog at scale
|
||||||
|
await tester.longPress(
|
||||||
|
find.textContaining('Checking layout on 320dp screen'),
|
||||||
|
);
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
await tester.tap(find.byIcon(Icons.delete_outline));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
await tester.tap(find.text(_l10n.common_cancel));
|
||||||
|
await _pumpFrames(tester);
|
||||||
|
|
||||||
|
await tester.pumpWidget(const SizedBox());
|
||||||
|
await tester.pump(const Duration(minutes: 1));
|
||||||
|
FlutterError.onError = previous;
|
||||||
|
|
||||||
|
expect(overflows, isEmpty, reason: overflows.join('\n'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -373,6 +373,7 @@ void main() {
|
|||||||
expect(_openMenuEntries(tester), [
|
expect(_openMenuEntries(tester), [
|
||||||
_l10n.addContact_title,
|
_l10n.addContact_title,
|
||||||
_l10n.discoveredContacts_Title,
|
_l10n.discoveredContacts_Title,
|
||||||
|
_l10n.bookmarks_title,
|
||||||
'---',
|
'---',
|
||||||
_l10n.contacts_zeroHopAdvert,
|
_l10n.contacts_zeroHopAdvert,
|
||||||
_l10n.contacts_floodAdvert,
|
_l10n.contacts_floodAdvert,
|
||||||
@@ -387,6 +388,7 @@ void main() {
|
|||||||
_menuItemByLabel(_l10n.discoveredContacts_Title).enabled,
|
_menuItemByLabel(_l10n.discoveredContacts_Title).enabled,
|
||||||
isTrue,
|
isTrue,
|
||||||
);
|
);
|
||||||
|
expect(_menuItemByLabel(_l10n.bookmarks_title).enabled, isTrue);
|
||||||
expect(
|
expect(
|
||||||
_menuItemByLabel(_l10n.contacts_zeroHopAdvert).enabled,
|
_menuItemByLabel(_l10n.contacts_zeroHopAdvert).enabled,
|
||||||
connected,
|
connected,
|
||||||
|
|||||||
Reference in new issue
Block a user