diff --git a/lib/app/features/feed/providers/replies_provider.c.dart b/lib/app/features/feed/providers/replies_provider.c.dart new file mode 100644 index 000000000..ba1db4115 --- /dev/null +++ b/lib/app/features/feed/providers/replies_provider.c.dart @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: ice License 1.0 + +import 'package:ion/app/features/feed/data/models/entities/post_data.c.dart'; +import 'package:ion/app/features/feed/providers/replies_data_source_provider.c.dart'; +import 'package:ion/app/features/nostr/model/event_reference.c.dart'; +import 'package:ion/app/features/nostr/model/nostr_entity.dart'; +import 'package:ion/app/features/nostr/providers/entities_paged_data_provider.c.dart'; +import 'package:ion/app/features/nostr/providers/nostr_cache.c.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; + +part 'replies_provider.c.g.dart'; + +@riverpod +class Replies extends _$Replies { + @override + EntitiesPagedDataState? build(EventReference eventReference) { + final dataSource = ref.watch(repliesDataSourceProvider(eventReference: eventReference)); + final entitiesPagedData = ref.watch(entitiesPagedDataProvider(dataSource)); + + final subscription = ref + .watch(nostrCacheStreamProvider) + .where((entity) => _isReply(entity, eventReference)) + .distinct() + .listen((entity) { + state = state?.copyWith.data(items: {entity, ...state?.data.items ?? {}}); + }); + ref.onDispose(subscription.cancel); + + return entitiesPagedData; + } + + bool _isReply(NostrEntity entity, EventReference parentEventReference) { + return entity is PostEntity && entity.data.parentEvent?.eventId == parentEventReference.eventId; + } +} diff --git a/lib/app/features/feed/views/pages/post_details_page/components/reply_list/reply_list.dart b/lib/app/features/feed/views/pages/post_details_page/components/reply_list/reply_list.dart index 23dc8324c..d59f6ebae 100644 --- a/lib/app/features/feed/views/pages/post_details_page/components/reply_list/reply_list.dart +++ b/lib/app/features/feed/views/pages/post_details_page/components/reply_list/reply_list.dart @@ -5,9 +5,8 @@ import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:ion/app/extensions/extensions.dart'; import 'package:ion/app/features/components/entities_list/entities_list.dart'; import 'package:ion/app/features/components/entities_list/entities_list_skeleton.dart'; -import 'package:ion/app/features/feed/providers/replies_data_source_provider.c.dart'; +import 'package:ion/app/features/feed/providers/replies_provider.c.dart'; import 'package:ion/app/features/nostr/model/event_reference.c.dart'; -import 'package:ion/app/features/nostr/providers/entities_paged_data_provider.c.dart'; class ReplyList extends ConsumerWidget { const ReplyList({required this.eventReference, super.key}); @@ -16,9 +15,8 @@ class ReplyList extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final dataSource = ref.watch(repliesDataSourceProvider(eventReference: eventReference)); - final entitiesPagedData = ref.watch(entitiesPagedDataProvider(dataSource)); - final entities = entitiesPagedData?.data.items; + final replies = ref.watch(repliesProvider(eventReference)); + final entities = replies?.data.items; if (entities == null) { return const EntitiesListSkeleton();