Skip to content

Commit

Permalink
fix(bookmarks): correctly handle first ever bookmark use case
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-ajax committed Jan 3, 2025
1 parent 08152cb commit f59b602
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/app/features/feed/providers/bookmarks_notifier.c.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class BookmarksNotifier extends _$BookmarksNotifier {

final bookmarksMap = await ref.read(currentUserBookmarksProvider.future);
final bookmarksSet = bookmarksMap[type];
final bookmarksSetsData = bookmarksMap.map((key, value) => MapEntry(key, value?.data));

if (nostrEntity is PostEntity) {
final postId = nostrEntity.id;
Expand All @@ -145,7 +146,7 @@ class BookmarksNotifier extends _$BookmarksNotifier {
articlesRefs: bookmarksSet?.data.articlesRefs ?? [],
);

bookmarksMap[type] = bookmarksSet?.copyWith(data: newSingleBookmarksSetData);
bookmarksSetsData[type] = newSingleBookmarksSetData;
} else if (nostrEntity is ArticleEntity) {
final articleRef = nostrEntity.toReplaceableEventReference();
final bookmarksRefs =
Expand All @@ -162,20 +163,20 @@ class BookmarksNotifier extends _$BookmarksNotifier {
articlesRefs: bookmarksRefs.toList(),
);

bookmarksMap[type] = bookmarksSet?.copyWith(data: newSingleBookmarksSetData);
bookmarksSetsData[type] = newSingleBookmarksSetData;
}

final bookmarksData = BookmarksData(
ids: [],
bookmarksSetRefs: bookmarksMap.values
.map((bookmarksSet) => bookmarksSet?.data.toReplaceableEventReference(currentPubkey))
bookmarksSetRefs: bookmarksSetsData.values
.map((data) => data?.toReplaceableEventReference(currentPubkey))
.whereNotNull()
.toList(),
);

await ref
.read(nostrNotifierProvider.notifier)
.sendEntitiesData([bookmarksMap[type]!.data, bookmarksData]);
.sendEntitiesData([bookmarksSetsData[type]!, bookmarksData]);
});
}
}

0 comments on commit f59b602

Please sign in to comment.