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

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

No files matched your search

+3 -1
View File
@@ -31,7 +31,7 @@ QuickSwitchBar tab 1 (middle) from any main screen.
- Unread badge (if messages are unread)
- Drag handle (when manual sort is active)
- **"+" FAB** to add a new channel
- **Overflow menu**: Disconnect, Manage Communities, Settings
- **Overflow menu**: Disconnect, Bookmarks, Manage Communities, Settings
If no channels exist, an empty state with an "Add Public Channel" shortcut is shown. If a search produces no results, a separate "no results" empty state with a search-off icon is shown.
@@ -79,6 +79,7 @@ Tap a channel card to open the channel chat screen.
- Tap the title or landscape icon to select a region; see [Regions](regions.md)
- Overflow menu (⋮) → **Notifications**: choose all messages, mentions only or muted for this channel. The row shows the current mode
- Overflow menu (⋮) → **Edit channel** and **Delete channel**: the same sheet and confirmation as a long-press in the channel list
- Overflow menu (⋮) → **Show bookmarks** toggles the channel's bookmarked-message filter; the bookmark icon is filled while active and outlined while inactive.
- Overflow menu (⋮) → **Chat background**: a color or picture, with a fade slider, behind this channel only. See [Chat backgrounds](themes.md#chat-backgrounds). Holiday greetings in new messages play a short animation, as in [direct chat](chat-and-messaging.md#message-list)
### Message Display
@@ -87,6 +88,7 @@ Tap a channel card to open the channel chat screen.
- **Incoming messages**: Colored avatar with sender's initial (or first emoji if name starts with one; color is deterministic from sender name hash), sender name in primary color, message bubble
- **Outgoing messages**: Primary container color bubble with a small status icon: pending (clock), sent (checkmark), or failed (red error circle)
- Automatic older-message loading on scroll-to-top
- Long-press a message and choose **Bookmark** to mark it with a yellow icon. Bookmarks are stored separately from channel history and remain available after a channel is deleted.
- Jump-to-bottom button when scrolled up
- **Pinch-to-zoom**: Two-finger zoom (0.8x–1.8x) and double-tap to reset text size
- **Message tracing mode** (when enabled in App Settings): Each bubble additionally shows path prefix bytes (`via XX,YY,...`), a timestamp, and a repeat count icon
+1
View File
@@ -29,6 +29,7 @@ From the Contacts screen, tap any Chat-type contact to open the ChatScreen.
- **Holiday animations**: A new message with a holiday greeting ("Happy Halloween", "Merry Christmas", and so on, in any app language) plays a short animation. Turn off in App Settings → Appearance; see [Holiday message animations](themes.md#holiday-message-animations)
- **Outgoing messages**: Right-aligned, primary color background. **Failed messages** change to a red-toned error container background
- **Incoming messages**: Left-aligned, grey background with a colored avatar (initial letter or first emoji of sender name; color is deterministic from a hash of the sender name)
- Long-press a message and choose **Bookmark** to show a yellow bookmark on the bubble. **Show bookmarks** in the chat menu toggles a filter for bookmarked messages; use **Bookmarks** in the Channels screen menu to browse saved messages, including those from deleted contacts or channels. From the bookmarks list, copy a message with its copy button. Links remain tappable, and supported URL-image previews are shown when **Load images from links** is enabled in App Settings.
- Bubble width capped at 72% of screen width
- Hyperlinks rendered as tappable green underlined text
- Message text follows the system font size (Android/iOS accessibility text size); pinch-to-zoom scales on top of it
+64
View File
@@ -12,6 +12,7 @@ import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_
import '../utils/advert_signature.dart';
import '../models/channel.dart';
import '../models/channel_message.dart';
import '../models/bookmarked_message.dart';
import '../models/companion_radio_stats.dart';
import '../models/contact.dart';
import '../models/message_filter.dart';
@@ -50,6 +51,7 @@ import '../services/notification_reply.dart';
import '../services/notification_service.dart';
import 'meshcore_connector_usb.dart';
import 'meshcore_connector_tcp.dart';
import '../storage/bookmark_store.dart';
import '../storage/channel_message_store.dart';
import '../storage/channel_order_store.dart';
import '../storage/channel_settings_store.dart';
@@ -514,6 +516,7 @@ class MeshCoreConnector extends ChangeNotifier {
// batched here; see [CoalescedWrites].
final CoalescedWrites _coalescedWrites = CoalescedWrites();
final MessageStore _messageStore = MessageStore();
final BookmarkStore _bookmarkStore = BookmarkStore();
final ChannelOrderStore _channelOrderStore = ChannelOrderStore();
final ChannelSettingsStore _channelSettingsStore = ChannelSettingsStore();
final ChannelRegionStore _channelRegionStore = ChannelRegionStore();
@@ -961,6 +964,66 @@ class MeshCoreConnector extends ChangeNotifier {
return _conversations[contact.publicKeyHex] ?? [];
}
Future<List<BookmarkedMessage>> loadBookmarkedMessages() =>
_bookmarkStore.loadBookmarks();
Future<void> setBookmarkedMessage(
BookmarkedMessage bookmark, {
required bool isBookmarked,
}) async {
if (_bookmarkStore.publicKeyHex.isEmpty) return;
if (isBookmarked) {
await _bookmarkStore.saveBookmark(bookmark);
} else {
await _bookmarkStore.removeBookmark(bookmark);
}
if (bookmark.sourceType == BookmarkSourceType.contact) {
final messages = _conversations[bookmark.sourceId];
final index = messages?.indexWhere(
(message) => message.messageId == bookmark.messageId,
);
if (messages != null && index != null && index >= 0) {
messages[index] = messages[index].copyWith(isBookmarked: isBookmarked);
await _coalescedWrites.flush();
await _messageStore.saveMessages(bookmark.sourceId, messages);
}
await _messageStore.updateBookmarkFlag(
bookmark.sourceId,
bookmark.messageId,
isBookmarked,
);
} else {
final mappedSlot = _slotForChannelId(bookmark.sourceId);
final slot =
mappedSlot ??
(bookmark.sourceId.startsWith('slot:')
? int.tryParse(bookmark.sourceId.substring(5))
: null);
if (slot != null) {
final canonicalSlot = _canonicalSlot(slot);
final messages = _channelMessages[canonicalSlot];
final index = messages?.indexWhere(
(message) => message.messageId == bookmark.messageId,
);
if (messages != null && index != null && index >= 0) {
messages[index] = messages[index].copyWith(
isBookmarked: isBookmarked,
);
await _saveChannelMessages(canonicalSlot, messages);
}
}
if (!bookmark.sourceId.startsWith('slot:')) {
await _channelMessageStore.updateBookmarkFlag(
bookmark.sourceId,
bookmark.messageId,
isBookmarked,
);
}
}
notifyListeners();
}
Future<void> deleteMessage(Message message) async {
final contactKeyHex = message.senderKeyHex;
final messages = _conversations[contactKeyHex];
@@ -9609,6 +9672,7 @@ class MeshCoreConnector extends ChangeNotifier {
unawaited(_unreadStore.flush());
_channelMessageStore.setPublicKeyHex = keyHex;
_messageStore.setPublicKeyHex = keyHex;
_bookmarkStore.setPublicKeyHex = keyHex;
_channelOrderStore.setPublicKeyHex = keyHex;
_channelSettingsStore.setPublicKeyHex = keyHex;
_channelRegionStore.setPublicKeyHex = keyHex;
+8
View File
@@ -1128,6 +1128,14 @@
},
"chat_messageCopied": "Message copied",
"chat_messageDeleted": "Message deleted",
"chat_bookmark": "Bookmark",
"chat_removeBookmark": "Remove bookmark",
"chat_showBookmarks": "Show bookmarks",
"bookmarks_title": "Bookmarks",
"bookmarks_empty": "No bookmarked messages",
"bookmarks_channel": "Channel",
"bookmarks_contact": "Contact",
"bookmarks_remove": "Remove bookmark",
"chat_selectMessages": "Select messages",
"chat_selectedCount": "{count} selected",
"@chat_selectedCount": {
+48
View File
@@ -4039,6 +4039,54 @@ abstract class AppLocalizations {
/// **'Message deleted'**
String get chat_messageDeleted;
/// No description provided for @chat_bookmark.
///
/// In en, this message translates to:
/// **'Bookmark'**
String get chat_bookmark;
/// No description provided for @chat_removeBookmark.
///
/// In en, this message translates to:
/// **'Remove bookmark'**
String get chat_removeBookmark;
/// No description provided for @chat_showBookmarks.
///
/// In en, this message translates to:
/// **'Show bookmarks'**
String get chat_showBookmarks;
/// No description provided for @bookmarks_title.
///
/// In en, this message translates to:
/// **'Bookmarks'**
String get bookmarks_title;
/// No description provided for @bookmarks_empty.
///
/// In en, this message translates to:
/// **'No bookmarked messages'**
String get bookmarks_empty;
/// No description provided for @bookmarks_channel.
///
/// In en, this message translates to:
/// **'Channel'**
String get bookmarks_channel;
/// No description provided for @bookmarks_contact.
///
/// In en, this message translates to:
/// **'Contact'**
String get bookmarks_contact;
/// No description provided for @bookmarks_remove.
///
/// In en, this message translates to:
/// **'Remove bookmark'**
String get bookmarks_remove;
/// No description provided for @chat_selectMessages.
///
/// In en, this message translates to:
+24
View File
@@ -2280,6 +2280,30 @@ class AppLocalizationsBg extends AppLocalizations {
@override
String get chat_messageDeleted => 'Съобщението е изтрито';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Избор на съобщения';
+24
View File
@@ -2264,6 +2264,30 @@ class AppLocalizationsCs extends AppLocalizations {
@override
String get chat_messageDeleted => 'Zpráva smazána';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Vybrat zprávy';
+24
View File
@@ -2284,6 +2284,30 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get chat_messageDeleted => 'Nachricht gelöscht';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Nachrichten auswählen';
+24
View File
@@ -2239,6 +2239,30 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get chat_messageDeleted => 'Message deleted';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Select messages';
+24
View File
@@ -2274,6 +2274,30 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get chat_messageDeleted => 'Mensaje borrado';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Seleccionar mensajes';
+24
View File
@@ -2279,6 +2279,30 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get chat_messageDeleted => 'Message supprimé';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Sélectionner des messages';
+24
View File
@@ -2272,6 +2272,30 @@ class AppLocalizationsHu extends AppLocalizations {
@override
String get chat_messageDeleted => 'Üzenet törölve';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Üzenetek kijelölése';
+24
View File
@@ -2276,6 +2276,30 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get chat_messageDeleted => 'Messaggio eliminato';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Seleziona messaggi';
+24
View File
@@ -2166,6 +2166,30 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get chat_messageDeleted => 'メッセージは削除されました';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'メッセージを選択';
+24
View File
@@ -2170,6 +2170,30 @@ class AppLocalizationsKo extends AppLocalizations {
@override
String get chat_messageDeleted => '메시지가 삭제되었습니다.';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => '메시지 선택';
+24
View File
@@ -2263,6 +2263,30 @@ class AppLocalizationsNl extends AppLocalizations {
@override
String get chat_messageDeleted => 'Bericht verwijderd';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Berichten selecteren';
+24
View File
@@ -2292,6 +2292,30 @@ class AppLocalizationsPl extends AppLocalizations {
@override
String get chat_messageDeleted => 'Wiadomość usunięta';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Wybierz wiadomości';
+24
View File
@@ -2273,6 +2273,30 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get chat_messageDeleted => 'Mensagem excluída';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Selecionar mensagens';
+24
View File
@@ -2273,6 +2273,30 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get chat_messageDeleted => 'Сообщение удалено';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Выбрать сообщения';
+24
View File
@@ -2266,6 +2266,30 @@ class AppLocalizationsSk extends AppLocalizations {
@override
String get chat_messageDeleted => 'Správa odstránená';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Vybrať správy';
+24
View File
@@ -2266,6 +2266,30 @@ class AppLocalizationsSl extends AppLocalizations {
@override
String get chat_messageDeleted => 'Sporočilo izbrisano';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Izberi sporočila';
+24
View File
@@ -2252,6 +2252,30 @@ class AppLocalizationsSv extends AppLocalizations {
@override
String get chat_messageDeleted => 'Meddelandet raderat';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Markera meddelanden';
+24
View File
@@ -2269,6 +2269,30 @@ class AppLocalizationsUk extends AppLocalizations {
@override
String get chat_messageDeleted => 'Повідомлення видалено';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => 'Вибрати повідомлення';
+24
View File
@@ -2138,6 +2138,30 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get chat_messageDeleted => '消息已删除';
@override
String get chat_bookmark => 'Bookmark';
@override
String get chat_removeBookmark => 'Remove bookmark';
@override
String get chat_showBookmarks => 'Show bookmarks';
@override
String get bookmarks_title => 'Bookmarks';
@override
String get bookmarks_empty => 'No bookmarked messages';
@override
String get bookmarks_channel => 'Channel';
@override
String get bookmarks_contact => 'Contact';
@override
String get bookmarks_remove => 'Remove bookmark';
@override
String get chat_selectMessages => '选择消息';
+110
View File
@@ -0,0 +1,110 @@
import 'package:flutter/foundation.dart';
import 'channel_message.dart';
import 'message.dart';
enum BookmarkSourceType { contact, channel }
@immutable
class BookmarkedMessage {
final BookmarkSourceType sourceType;
final String sourceId;
final String sourceName;
final String messageId;
final String senderName;
final String text;
final String? translatedText;
final DateTime timestamp;
final DateTime receivedAt;
final bool isOutgoing;
const BookmarkedMessage({
required this.sourceType,
required this.sourceId,
required this.sourceName,
required this.messageId,
required this.senderName,
required this.text,
required this.timestamp,
required this.receivedAt,
required this.isOutgoing,
this.translatedText,
});
factory BookmarkedMessage.fromContact({
required Message message,
required String contactKey,
required String contactName,
required String senderName,
}) => BookmarkedMessage(
sourceType: BookmarkSourceType.contact,
sourceId: contactKey,
sourceName: contactName,
messageId: message.messageId,
senderName: senderName,
text: message.text,
translatedText: message.translatedText,
timestamp: message.timestamp,
receivedAt: message.receivedAt,
isOutgoing: message.isOutgoing,
);
factory BookmarkedMessage.fromChannel({
required ChannelMessage message,
required String channelId,
required String channelName,
required String senderName,
}) => BookmarkedMessage(
sourceType: BookmarkSourceType.channel,
sourceId: channelId,
sourceName: channelName,
messageId: message.messageId,
senderName: senderName,
text: message.text,
translatedText: message.translatedText,
timestamp: message.timestamp,
receivedAt: message.receivedAt,
isOutgoing: message.isOutgoing,
);
String get storageId => storageIdFor(sourceType, sourceId, messageId);
static String storageIdFor(
BookmarkSourceType sourceType,
String sourceId,
String messageId,
) => '${sourceType.name}:$sourceId:$messageId';
Map<String, Object?> toJson() => {
'sourceType': sourceType.name,
'sourceId': sourceId,
'sourceName': sourceName,
'messageId': messageId,
'senderName': senderName,
'text': text,
'translatedText': translatedText,
'timestamp': timestamp.millisecondsSinceEpoch,
'receivedAt': receivedAt.millisecondsSinceEpoch,
'isOutgoing': isOutgoing,
};
factory BookmarkedMessage.fromJson(Map<String, dynamic> json) {
final type = BookmarkSourceType.values.firstWhere(
(value) => value.name == json['sourceType'],
);
return BookmarkedMessage(
sourceType: type,
sourceId: json['sourceId'] as String,
sourceName: json['sourceName'] as String,
messageId: json['messageId'] as String,
senderName: json['senderName'] as String,
text: json['text'] as String,
translatedText: json['translatedText'] as String?,
timestamp: DateTime.fromMillisecondsSinceEpoch(json['timestamp'] as int),
receivedAt: DateTime.fromMillisecondsSinceEpoch(
json['receivedAt'] as int? ?? json['timestamp'] as int,
),
isOutgoing: json['isOutgoing'] as bool? ?? false,
);
}
}
+4
View File
@@ -43,6 +43,7 @@ class ChannelMessage {
/// to the bottom; [timestamp] stays the sender's identity time.
final DateTime receivedAt;
final bool isOutgoing;
final bool isBookmarked;
final ChannelMessageStatus status;
final List<Repeat> repeats;
final int repeatCount;
@@ -77,6 +78,7 @@ class ChannelMessage {
required this.timestamp,
DateTime? receivedAt,
required this.isOutgoing,
this.isBookmarked = false,
this.status = ChannelMessageStatus.pending,
this.repeats = const [],
this.repeatCount = 0,
@@ -117,6 +119,7 @@ class ChannelMessage {
ChannelMessage copyWith({
ChannelMessageStatus? status,
bool? isBookmarked,
List<Repeat>? repeats,
int? repeatCount,
int? pathLength,
@@ -159,6 +162,7 @@ class ChannelMessage {
timestamp: timestamp,
receivedAt: receivedAt,
isOutgoing: isOutgoing,
isBookmarked: isBookmarked ?? this.isBookmarked,
status: status ?? this.status,
repeats: repeats ?? this.repeats,
repeatCount: repeatCount ?? this.repeatCount,
+4
View File
@@ -34,6 +34,7 @@ class Message {
/// to the bottom; [timestamp] stays the sender's identity time.
final DateTime receivedAt;
final bool isOutgoing;
final bool isBookmarked;
final bool isCli;
final MessageStatus status;
final String? originalText;
@@ -62,6 +63,7 @@ class Message {
required this.timestamp,
DateTime? receivedAt,
required this.isOutgoing,
this.isBookmarked = false,
this.isCli = false,
this.status = MessageStatus.pending,
String? messageId,
@@ -108,6 +110,7 @@ class Message {
int? pathLength,
Uint8List? pathBytes,
bool? isCli,
bool? isBookmarked,
Object? originalText = _unset,
Object? translatedText = _unset,
Object? translatedLanguageCode = _unset,
@@ -123,6 +126,7 @@ class Message {
timestamp: timestamp,
receivedAt: receivedAt,
isOutgoing: isOutgoing,
isBookmarked: isBookmarked ?? this.isBookmarked,
isCli: isCli ?? this.isCli,
status: status ?? this.status,
messageId: messageId,
+178
View File
@@ -0,0 +1,178 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import '../connector/meshcore_connector.dart';
import '../helpers/message_url_image_helper.dart';
import '../l10n/l10n.dart';
import '../models/bookmarked_message.dart';
import '../services/app_settings_service.dart';
import '../widgets/chat_send_pipeline.dart';
import '../widgets/empty_state.dart';
import '../widgets/translated_message_content.dart';
class BookmarksScreen extends StatefulWidget {
const BookmarksScreen({super.key});
@override
State<BookmarksScreen> createState() => _BookmarksScreenState();
}
class _BookmarksScreenState extends State<BookmarksScreen> {
late Future<List<BookmarkedMessage>> _bookmarks;
@override
void initState() {
super.initState();
_bookmarks = context.read<MeshCoreConnector>().loadBookmarkedMessages();
}
void _reload() {
setState(() {
_bookmarks = context.read<MeshCoreConnector>().loadBookmarkedMessages();
});
}
Future<void> _remove(BookmarkedMessage bookmark) async {
await context.read<MeshCoreConnector>().setBookmarkedMessage(
bookmark,
isBookmarked: false,
);
if (mounted) _reload();
}
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final publicIpfsGateway = context
.watch<AppSettingsService>()
.settings
.publicIpfsGateway;
final dateFormat = DateFormat.yMd(
Localizations.localeOf(context).toString(),
).add_Hm();
return Scaffold(
appBar: AppBar(title: Text(l10n.bookmarks_title), centerTitle: true),
body: FutureBuilder<List<BookmarkedMessage>>(
future: _bookmarks,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const Center(child: CircularProgressIndicator());
}
final bookmarks = snapshot.data ?? const <BookmarkedMessage>[];
if (bookmarks.isEmpty) {
return EmptyState(
icon: Icons.bookmark_border,
title: l10n.bookmarks_empty,
);
}
bookmarks.sort((a, b) => b.receivedAt.compareTo(a.receivedAt));
return ListView.builder(
padding: const EdgeInsets.all(12),
itemCount: bookmarks.length,
itemBuilder: (context, index) {
final bookmark = bookmarks[index];
final sourceType =
bookmark.sourceType == BookmarkSourceType.channel
? l10n.bookmarks_channel
: l10n.bookmarks_contact;
final time = dateFormat.format(bookmark.receivedAt.toLocal());
final translation = bookmark.translatedText?.trim();
final displayText = translation?.isNotEmpty == true
? translation!
: bookmark.text;
final textStyle =
Theme.of(context).textTheme.bodyMedium ?? const TextStyle();
final textContent = TranslatedMessageContent(
displayText: displayText,
originalText: displayText == bookmark.text
? null
: bookmark.text,
style: textStyle,
originalStyle: textStyle.copyWith(fontStyle: FontStyle.italic),
);
return Card(
margin: const EdgeInsets.only(bottom: 10),
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 8, 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.only(top: 2, right: 8),
child: Icon(
Icons.bookmark,
size: 20,
color: Color(0xFFFFE54A),
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'$sourceType · ${bookmark.sourceName}',
style: Theme.of(context).textTheme.titleSmall,
),
const SizedBox(height: 2),
Text(
'${bookmark.senderName} · $time',
style: Theme.of(context).textTheme.bodySmall,
),
],
),
),
IconButton(
tooltip: l10n.common_copy,
onPressed: () =>
copyChatMessageText(context, bookmark.text),
icon: const Icon(Icons.copy),
),
IconButton(
tooltip: l10n.bookmarks_remove,
onPressed: () => _remove(bookmark),
icon: const Icon(Icons.bookmark_remove_outlined),
),
],
),
const SizedBox(height: 8),
if (MessageUrlImageHelper.hasPotentialImageUrl(
bookmark.text,
))
MessageUrlImageFutureBuilder(
messageId: bookmark.messageId,
text: bookmark.text,
publicGateway: publicIpfsGateway,
builder: (context, snapshot) {
final imageUrl = snapshot.data;
if (imageUrl == null) return textContent;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: MessageUrlImagePreview(
imageUrl: imageUrl,
),
),
textContent,
],
);
},
)
else
textContent,
],
),
),
);
},
);
},
),
);
}
}
+80 -11
View File
@@ -31,6 +31,7 @@ import '../helpers/snack_bar_builder.dart';
import '../l10n/l10n.dart';
import '../models/channel.dart';
import '../models/channel_message.dart';
import '../models/bookmarked_message.dart';
import '../models/image_codec_support.dart' show aeicRatePointForUi;
import '../models/message_filter.dart';
import '../services/app_settings_service.dart' show AppSettingsService;
@@ -165,6 +166,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
/// Message ids picked for a bulk action. Non-empty means selection mode:
/// taps toggle messages and the app bar shows the bulk actions.
final Set<String> _selectedIds = <String>{};
bool _showBookmarkedOnly = false;
bool get _selecting => _selectedIds.isNotEmpty;
@override
@@ -574,6 +576,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
widget.channel,
onSaved: _onChannelEdited,
);
case 'showBookmarks':
setState(() {
_showBookmarkedOnly = !_showBookmarkedOnly;
_selectedIds.clear();
});
case 'background':
showChatBackgroundSheet(
context,
@@ -629,6 +636,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
enabled: !readOnly,
child: _menuRow(Icons.settings, context.l10n.channels_editChannel),
),
PopupMenuItem(
value: 'showBookmarks',
child: _menuRow(
_showBookmarkedOnly ? Icons.bookmark : Icons.bookmark_border,
context.l10n.chat_showBookmarks,
color: _showBookmarkedOnly ? const Color(0xFFFFE54A) : null,
),
),
PopupMenuItem(
value: 'background',
child: _menuRow(Icons.wallpaper, context.l10n.chatBackground_title),
@@ -856,13 +871,22 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
final layout = _transcriptLayoutFor(
context,
messages,
showBookmarkedOnly: _showBookmarkedOnly,
);
// Fewer entries than messages means the filter hid or
// collapsed some; make sure older history stays reachable.
final hidesMessages = layout.length < messages.length;
// Fewer entries than messages means the message filter
// hid or collapsed some; bookmark filtering is deliberate.
final hidesMessages =
!_showBookmarkedOnly &&
layout.length < messages.length;
if (hidesMessages) _scheduleHiddenHistoryBackfill();
if (layout.length == 0) {
if (_showBookmarkedOnly) {
return EmptyState(
icon: Icons.bookmark_border,
title: context.l10n.bookmarks_empty,
);
}
final canLoadOlder =
hidesMessages && !_olderHistoryExhausted;
return EmptyState(
@@ -1167,6 +1191,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
: null,
child: MessageBubbleFrame(
isOutgoing: isOutgoing,
isBookmarked: message.isBookmarked || _showBookmarkedOnly,
compact: gifId != null,
maxWidth: constraints.maxWidth,
child: Column(
@@ -2187,8 +2212,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
/// `State`'s) — `watch` asserts on that.
_TranscriptLayout _transcriptLayoutFor(
BuildContext context,
List<ChannelMessage> messages,
) {
List<ChannelMessage> messages, {
bool showBookmarkedOnly = false,
}) {
ReceivedImageStore? store;
try {
store = context.watch<ReceivedImageStore>();
@@ -2217,10 +2243,17 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
displayMode,
filterActive,
_revealVersion,
showBookmarkedOnly,
_filteredMessagesSignature(messages),
Object.hashAll(
messages
.where((message) => message.isBookmarked)
.map((message) => message.messageId),
),
);
final cached = _transcriptLayout;
if (cached != null &&
if (!showBookmarkedOnly &&
cached != null &&
cached.matches(
messages,
_imageStoreVersion,
@@ -2229,11 +2262,14 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
)) {
return cached;
}
final images = store == null
final displayedMessages = showBookmarkedOnly
? messages.where((message) => message.isBookmarked).toList()
: messages;
final images = store == null || showBookmarkedOnly
? const <ReceivedImageEntry>[]
: store.entriesForChannel(widget.channel.storageId);
final layout = _TranscriptLayout.build(
messages: messages,
messages: displayedMessages,
images: images,
imageVersion: _imageStoreVersion,
channelIndex: widget.channel.index,
@@ -2994,6 +3030,38 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
_markAsUnread(message);
},
),
ListTile(
leading: Icon(
message.isBookmarked
? Icons.bookmark_remove_outlined
: Icons.bookmark_add_outlined,
),
title: Text(
message.isBookmarked
? context.l10n.chat_removeBookmark
: context.l10n.chat_bookmark,
),
onTap: () {
Navigator.pop(sheetContext);
final bookmark = BookmarkedMessage.fromChannel(
message: message,
channelId:
widget.channel.storageId ??
'slot:${widget.channel.index}',
channelName: widget.channel.name,
senderName: message.isOutgoing
? (context.read<MeshCoreConnector>().selfName ??
context.l10n.chat_me)
: message.senderName,
);
unawaited(
context.read<MeshCoreConnector>().setBookmarkedMessage(
bookmark,
isBookmarked: !message.isBookmarked,
),
);
},
),
if (showFilterActions) ...[
const Divider(height: 1),
if (message.isFiltered)
@@ -3094,9 +3162,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
final filterActive = _transcriptLayout?.filterActive ?? true;
return [
for (final m in messages)
if (!(filterActive &&
m.isFiltered &&
!_revealedFilteredIds.contains(m.messageId)))
if ((!_showBookmarkedOnly || m.isBookmarked) &&
!(filterActive &&
m.isFiltered &&
!_revealedFilteredIds.contains(m.messageId)))
m,
];
}
+11
View File
@@ -34,6 +34,7 @@ import '../helpers/contact_share_message.dart';
import '../helpers/gif_helper.dart';
import '../helpers/snack_bar_builder.dart';
import '../helpers/utf8_length_limiter.dart';
import 'bookmarks_screen.dart';
import 'channel_chat_screen.dart';
import 'community_qr_scanner_screen.dart';
import 'contacts_screen.dart';
@@ -128,6 +129,16 @@ class _ChannelsScreenState extends State<ChannelsScreen> {
// context, which is deactivated by then.
itemBuilder: (menuContext) => [
connectionMenuItem(context, menuContext),
PopupMenuItem(
child: MeshMenuItemRow(
icon: Icons.bookmark_border,
label: menuContext.l10n.bookmarks_title,
),
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const BookmarksScreen()),
),
),
PopupMenuItem(
child: MeshMenuItemRow(
icon: Icons.groups,
+65 -1
View File
@@ -28,6 +28,7 @@ import '../helpers/marker_message.dart';
import '../helpers/message_search.dart';
import '../widgets/chat_search_results.dart';
import '../models/channel_message.dart';
import '../models/bookmarked_message.dart';
import '../models/contact.dart';
import '../l10n/contact_localization.dart';
import '../models/message.dart';
@@ -96,6 +97,7 @@ class _ChatScreenState extends State<ChatScreen> {
final _textFieldFocusNode = FocusNode();
final GlobalKey _unreadScrollKey = GlobalKey();
bool _isLoadingOlder = false;
bool _showBookmarkedOnly = false;
MeshCoreConnector? _connector;
Message? _pendingUnreadScrollTarget;
String? _unreadDividerMessageId;
@@ -484,6 +486,10 @@ class _ChatScreenState extends State<ChatScreen> {
_showContactInfo(context);
case 'settings':
_showContactSettings(context);
case 'showBookmarks':
setState(
() => _showBookmarkedOnly = !_showBookmarkedOnly,
);
case 'background':
showChatBackgroundSheet(
context,
@@ -551,6 +557,18 @@ class _ChatScreenState extends State<ChatScreen> {
label: context.l10n.contact_settings,
),
),
PopupMenuItem(
value: 'showBookmarks',
child: MeshMenuItemRow(
icon: _showBookmarkedOnly
? Icons.bookmark
: Icons.bookmark_border,
label: context.l10n.chat_showBookmarks,
color: _showBookmarkedOnly
? const Color(0xFFFFE54A)
: null,
),
),
PopupMenuItem(
value: 'background',
child: MeshMenuItemRow(
@@ -631,6 +649,7 @@ class _ChatScreenState extends State<ChatScreen> {
}
Widget _buildEmptyState() {
if (_showBookmarkedOnly) return _buildBookmarkEmptyState();
return EmptyState(
icon: Icons.chat_bubble_outline,
title: context.l10n.chat_noMessages,
@@ -640,12 +659,23 @@ class _ChatScreenState extends State<ChatScreen> {
);
}
Widget _buildBookmarkEmptyState() => EmptyState(
icon: Icons.bookmark_border,
title: context.l10n.bookmarks_empty,
);
Widget _buildMessageList(
List<Message> messages,
MeshCoreConnector connector,
) {
final visibleMessages = _showBookmarkedOnly
? messages.where((message) => message.isBookmarked).toList()
: messages;
if (_showBookmarkedOnly && visibleMessages.isEmpty) {
return _buildBookmarkEmptyState();
}
// Reverse messages so newest appear at bottom with reverse: true
final reversedMessages = messages.reversed.toList();
final reversedMessages = visibleMessages.reversed.toList();
final itemCount = reversedMessages.length + (_isLoadingOlder ? 1 : 0);
// Auto-scroll to bottom if user is already at bottom
@@ -713,6 +743,7 @@ class _ChatScreenState extends State<ChatScreen> {
: contact.name,
sourceId: widget.contact.publicKeyHex,
textScale: textScale,
isBookmarked: message.isBookmarked || _showBookmarkedOnly,
onLongPress: () => _showMessageActions(message, contact),
onRetryReaction: (msg, emoji) =>
_sendReaction(msg, contact, emoji),
@@ -1457,6 +1488,36 @@ class _ChatScreenState extends State<ChatScreen> {
_markAsUnread(message);
},
),
ListTile(
leading: Icon(
message.isBookmarked
? Icons.bookmark_remove_outlined
: Icons.bookmark_add_outlined,
),
title: Text(
message.isBookmarked
? context.l10n.chat_removeBookmark
: context.l10n.chat_bookmark,
),
onTap: () {
Navigator.pop(sheetContext);
final bookmark = BookmarkedMessage.fromContact(
message: message,
contactKey: widget.contact.publicKeyHex,
contactName: widget.contact.name,
senderName: message.isOutgoing
? (context.read<MeshCoreConnector>().selfName ??
context.l10n.chat_me)
: contact.name,
);
unawaited(
context.read<MeshCoreConnector>().setBookmarkedMessage(
bookmark,
isBookmarked: !message.isBookmarked,
),
);
},
),
if (message.isOutgoing && message.status == MessageStatus.failed)
ListTile(
enabled: !readOnly,
@@ -1567,12 +1628,14 @@ class _MessageBubble extends StatelessWidget {
final void Function(Message message, String emoji)? onRetryReaction;
final double textScale;
final String sourceId;
final bool isBookmarked;
const _MessageBubble({
required this.message,
required this.senderName,
required this.sourceId,
required this.textScale,
required this.isBookmarked,
this.onLongPress,
this.onRetryReaction,
});
@@ -1664,6 +1727,7 @@ class _MessageBubble extends StatelessWidget {
child: MessageBubbleFrame(
isOutgoing: isOutgoing,
isFailed: isFailed,
isBookmarked: isBookmarked,
compact: gifId != null,
maxWidth: constraints.maxWidth,
child: Column(
+92
View File
@@ -0,0 +1,92 @@
import 'dart:convert';
import '../models/bookmarked_message.dart';
import '../utils/app_logger.dart';
import 'prefs_manager.dart';
class BookmarkStore {
static const String _keyPrefix = 'message_bookmarks_';
String publicKeyHex = '';
set setPublicKeyHex(String value) =>
publicKeyHex = value.length > 10 ? value.substring(0, 10) : '';
String get keyFor => '$_keyPrefix$publicKeyHex';
Future<void> _pendingWrites = Future<void>.value();
Future<List<BookmarkedMessage>> loadBookmarks() async {
final writes = _pendingWrites;
await writes;
return _readBookmarks(keyFor);
}
Future<void> saveBookmark(BookmarkedMessage bookmark) {
if (publicKeyHex.isEmpty) return Future<void>.value();
final key = keyFor;
return _enqueue(() async {
final bookmarks = await _readBookmarks(key);
bookmarks.removeWhere(
(existing) => existing.storageId == bookmark.storageId,
);
bookmarks.add(bookmark);
await _writeBookmarks(key, bookmarks);
});
}
Future<void> removeBookmark(BookmarkedMessage bookmark) {
if (publicKeyHex.isEmpty) return Future<void>.value();
final key = keyFor;
return _enqueue(() async {
final bookmarks = await _readBookmarks(key);
bookmarks.removeWhere(
(existing) => existing.storageId == bookmark.storageId,
);
await _writeBookmarks(key, bookmarks);
});
}
Future<void> _enqueue(Future<void> Function() operation) {
final next = _pendingWrites.then((_) => operation());
_pendingWrites = next.then<void>(
(_) {},
onError: (Object _, StackTrace _) {},
);
return next;
}
Future<List<BookmarkedMessage>> _readBookmarks(String key) async {
if (key == _keyPrefix) return [];
final raw = PrefsManager.instance.getString(key);
if (raw == null || raw.isEmpty) return [];
try {
final decoded = jsonDecode(raw);
if (decoded is! List) return [];
final bookmarks = <BookmarkedMessage>[];
for (final value in decoded) {
if (value is! Map<String, dynamic>) continue;
try {
bookmarks.add(BookmarkedMessage.fromJson(value));
} on Object catch (error) {
appLogger.warn('Skipping malformed bookmark: $error');
}
}
return bookmarks;
} on FormatException catch (error) {
appLogger.warn('Stored bookmarks are unreadable: $error');
return [];
}
}
Future<void> _writeBookmarks(
String key,
List<BookmarkedMessage> bookmarks,
) async {
if (!await PrefsManager.instance.setString(
key,
jsonEncode(bookmarks.map((bookmark) => bookmark.toJson()).toList()),
)) {
throw StateError('Could not save bookmarks');
}
}
}
+12
View File
@@ -123,6 +123,16 @@ class ChannelMessageStore {
return messages;
}
Future<void> updateBookmarkFlag(
String channelId,
String messageId,
bool isBookmarked,
) => _archive.updateBookmarkFlag(
_keyForChannel(channelId),
messageId,
isBookmarked,
);
Future<void> clearChannelMessages(String channelId) =>
_archive.clear(HistoryStore.instance, _keyForChannel(channelId));
@@ -149,6 +159,7 @@ class ChannelMessageStore {
'timestamp': msg.timestamp.millisecondsSinceEpoch,
'receivedAt': msg.receivedAt.millisecondsSinceEpoch,
'isOutgoing': msg.isOutgoing,
'isBookmarked': msg.isBookmarked,
'status': msg.status.index,
'channelIndex': msg.channelIndex,
'region': msg.region,
@@ -226,6 +237,7 @@ class ChannelMessageStore {
timestamp: DateTime.fromMillisecondsSinceEpoch(json['timestamp'] as int),
receivedAt: legacyAwareReceivedAt(json),
isOutgoing: json['isOutgoing'] as bool? ?? false,
isBookmarked: json['isBookmarked'] as bool? ?? false,
status: _statusAt(json['status']) ?? ChannelMessageStatus.failed,
repeatCount: (json['repeatCount'] as int?) ?? 0,
pathLength: decodedPathLength,
+45
View File
@@ -121,6 +121,51 @@ class HistoryArchive {
(_archives[HistoryStore.instance] ??= {})[key] = _ArchiveState(count);
}
Future<void> updateBookmarkFlag(
String key,
String messageId,
bool isBookmarked,
) {
final store = HistoryStore.instance;
final state = _stateFor(store, key);
return _serialize(store, key, () async {
String? update(String raw) {
try {
final decoded = jsonDecode(raw);
if (decoded is! Map<String, dynamic> ||
mergeKey(decoded) != 'id:$messageId') {
return null;
}
decoded['isBookmarked'] = isBookmarked;
return jsonEncode(decoded);
} on FormatException {
return null;
}
}
for (var i = 0; i < state.pending.length; i++) {
final entry = state.pending[i];
final replacement = update(entry.$2);
if (replacement != null) state.pending[i] = (entry.$1, replacement);
}
final entries = await store.readEntries(key);
var changed = false;
final updated = <String>[];
for (final entry in entries) {
final replacement = update(entry);
updated.add(replacement ?? entry);
changed = changed || replacement != null;
}
if (changed &&
!await store.setString(
key,
jsonEncode(updated.map(jsonDecode).toList()),
)) {
throw StateError('Could not update message bookmark flag');
}
});
}
/// Only entries trimmed since the last successful save need buffering.
void archive(String key, Iterable<String> entries) {
final state = _stateFor(HistoryStore.instance, key);
+15
View File
@@ -175,6 +175,19 @@ class MessageStore {
return messages;
}
Future<void> updateBookmarkFlag(
String contactKeyHex,
String messageId,
bool isBookmarked,
) {
if (publicKeyHex.isEmpty) return Future<void>.value();
return _archive.updateBookmarkFlag(
'$keyFor$contactKeyHex',
messageId,
isBookmarked,
);
}
Future<void> clearMessages(String contactKeyHex) {
if (publicKeyHex.isEmpty) return Future<void>.value();
return _archive.clear(HistoryStore.instance, '$keyFor$contactKeyHex');
@@ -187,6 +200,7 @@ class MessageStore {
'timestamp': msg.timestamp.millisecondsSinceEpoch,
'receivedAt': msg.receivedAt.millisecondsSinceEpoch,
'isOutgoing': msg.isOutgoing,
'isBookmarked': msg.isBookmarked,
'isCli': msg.isCli,
'status': msg.status.index,
'messageId': msg.messageId,
@@ -257,6 +271,7 @@ class MessageStore {
timestamp: DateTime.fromMillisecondsSinceEpoch(json['timestamp'] as int),
receivedAt: legacyAwareReceivedAt(json),
isOutgoing: json['isOutgoing'] as bool? ?? false,
isBookmarked: json['isBookmarked'] as bool? ?? false,
isCli: isCli,
status: _statusAt(json['status']) ?? MessageStatus.failed,
messageId: json['messageId'] as String?,
+31 -11
View File
@@ -93,6 +93,7 @@ Color senderNameColor(String name) {
class MessageBubbleFrame extends StatelessWidget {
final bool isOutgoing;
final bool isFailed;
final bool isBookmarked;
/// Tighter padding for media (GIF) content.
final bool compact;
@@ -105,6 +106,7 @@ class MessageBubbleFrame extends StatelessWidget {
required this.maxWidth,
required this.child,
this.isFailed = false,
this.isBookmarked = false,
this.compact = false,
});
@@ -115,17 +117,35 @@ class MessageBubbleFrame extends StatelessWidget {
isOutgoing: isOutgoing,
isFailed: isFailed,
);
return Container(
padding: compact
? const EdgeInsets.all(4)
: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
constraints: BoxConstraints(maxWidth: maxWidth * 0.72),
decoration: BoxDecoration(
color: colors.background,
borderRadius: messageBubbleRadius(isOutgoing: isOutgoing),
border: Border.all(color: colors.border, width: 1),
),
child: child,
final contentPadding = compact
? const EdgeInsets.all(4)
: const EdgeInsets.symmetric(horizontal: 12, vertical: 8);
return Stack(
clipBehavior: Clip.none,
children: [
Container(
constraints: BoxConstraints(maxWidth: maxWidth * 0.72),
decoration: BoxDecoration(
color: colors.background,
borderRadius: messageBubbleRadius(isOutgoing: isOutgoing),
border: Border.all(color: colors.border, width: 1),
),
child: Padding(
padding: isBookmarked
? contentPadding.add(
EdgeInsets.only(top: compact ? 18 : 14, right: 14),
)
: contentPadding,
child: child,
),
),
if (isBookmarked)
const Positioned(
top: -2,
right: 12,
child: Icon(Icons.bookmark, size: 22, color: Color(0xFFFFE54A)),
),
],
);
}
}
+87
View File
@@ -0,0 +1,87 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/models/bookmarked_message.dart';
import 'package:meshcore_open/models/channel_message.dart';
import 'package:meshcore_open/storage/bookmark_store.dart';
import 'package:meshcore_open/storage/channel_message_store.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
const _deviceKey = 'abcdef012345';
const _channelId = 'channel-psk-id';
BookmarkedMessage _bookmark(
String id, {
BookmarkSourceType type = BookmarkSourceType.contact,
}) => BookmarkedMessage(
sourceType: type,
sourceId: type == BookmarkSourceType.channel ? _channelId : 'contact-key',
sourceName: type == BookmarkSourceType.channel ? 'Channel' : 'Contact',
messageId: id,
senderName: 'Alice',
text: 'saved text $id',
timestamp: DateTime.fromMillisecondsSinceEpoch(1000),
receivedAt: DateTime.fromMillisecondsSinceEpoch(2000),
isOutgoing: false,
);
Future<void> _init() async {
SharedPreferences.setMockInitialValues({});
PrefsManager.reset();
await PrefsManager.initialize();
}
void main() {
test('bookmarks persist independently of channel history', () async {
await _init();
final bookmarks = BookmarkStore()..setPublicKeyHex = _deviceKey;
final channelHistory = ChannelMessageStore()..setPublicKeyHex = _deviceKey;
await bookmarks.saveBookmark(
_bookmark('message-1', type: BookmarkSourceType.channel),
);
await channelHistory.saveChannelMessages(_channelId, [
ChannelMessage(
senderName: 'Alice',
text: 'saved text message-1',
timestamp: DateTime.fromMillisecondsSinceEpoch(1000),
isOutgoing: false,
messageId: 'message-1',
),
]);
await channelHistory.clearChannelMessages(_channelId);
final loaded = await bookmarks.loadBookmarks();
expect(loaded, hasLength(1));
expect(loaded.single.text, 'saved text message-1');
expect(loaded.single.sourceName, 'Channel');
});
test('bookmarks are isolated by radio and can be removed', () async {
await _init();
final store = BookmarkStore()..setPublicKeyHex = _deviceKey;
final bookmark = _bookmark('message-1');
await store.saveBookmark(bookmark);
store.setPublicKeyHex = '123456789abc';
expect(await store.loadBookmarks(), isEmpty);
store.setPublicKeyHex = _deviceKey;
await store.removeBookmark(bookmark);
expect(await store.loadBookmarks(), isEmpty);
});
test('queued saves retain bookmarks added together', () async {
await _init();
final store = BookmarkStore()..setPublicKeyHex = _deviceKey;
await Future.wait([
store.saveBookmark(_bookmark('one')),
store.saveBookmark(_bookmark('two')),
]);
expect(
(await store.loadBookmarks()).map((bookmark) => bookmark.messageId),
['one', 'two'],
);
});
}
@@ -191,6 +191,19 @@ void main() {
expect(reloaded.single.text, 'hi');
expect(reloaded.single.reactionStatuses, {'😀': MessageStatus.values[1]});
});
test('bookmark flags update in archived contact history', () async {
await _init();
final store = _messageStore();
await store.saveMessages(_contact, [_dm(0)]);
store.setArchivedCount(_contact, 1);
await store.updateBookmarkFlag(_contact, 'id0', true);
expect((await store.loadMessages(_contact)).single.isBookmarked, isTrue);
await store.updateBookmarkFlag(_contact, 'id0', false);
expect((await store.loadMessages(_contact)).single.isBookmarked, isFalse);
});
});
group('ChannelMessageStore window persistence', () {
@@ -224,6 +237,25 @@ void main() {
final reloaded = await store.loadChannelMessages(_channelId);
expect(reloaded.map((m) => m.text), ['c3']);
});
test('bookmark flags update in archived channel history', () async {
await _init();
final store = ChannelMessageStore()..setPublicKeyHex = _device;
await store.saveChannelMessages(_channelId, [_ch(0)]);
store.setArchivedCount(_channelId, 1);
await store.updateBookmarkFlag(_channelId, 'cid0', true);
expect(
(await store.loadChannelMessages(_channelId)).single.isBookmarked,
isTrue,
);
await store.updateBookmarkFlag(_channelId, 'cid0', false);
expect(
(await store.loadChannelMessages(_channelId)).single.isBookmarked,
isFalse,
);
});
});
group('Smaz.tryDecodePrefixed', () {
+210 -1
View File
@@ -1 +1,210 @@
{}
{
"bg": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"cs": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"de": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"es": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"fr": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"hu": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"it": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"ja": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"ko": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"nl": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"pl": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"pt": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"pt_PT": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"ru": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"sk": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"sl": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"sv": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"uk": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
],
"zh": [
"chat_bookmark",
"chat_removeBookmark",
"chat_showBookmarks",
"bookmarks_title",
"bookmarks_empty",
"bookmarks_channel",
"bookmarks_contact",
"bookmarks_remove"
]
}