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

+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', () {