diff --git a/lib/data_layer/repositories/note_repository_impl.dart b/lib/data_layer/repositories/note_repository_impl.dart index 02021d7..2077a28 100644 --- a/lib/data_layer/repositories/note_repository_impl.dart +++ b/lib/data_layer/repositories/note_repository_impl.dart @@ -232,23 +232,20 @@ class NoteRepositoryImpl implements NoteRepository { ); final response = dartNdkSource.dartNdk.requests.query( + timeout: 2, filters: [filter], - name: 'getReactions-${postId.substring(5, 10)}', + name: 'getReactions-${postId.substring(5, 10)}-', cacheRead: false, - cacheWrite: true, + cacheWrite: false, ); - return response.stream + final events = await response.future; + + return events .map( - (event) => NostrNoteModel.fromNDKEvent(event), - ) - .timeout( - const Duration(seconds: 2), - onTimeout: (sink) { - log('getReactions timeout'); - sink.close(); - }, - ).toList(); + (event) => NostrNoteModel.fromNDKEvent(event), + ) + .toList(); } @override diff --git a/lib/domain_layer/usecases/user_reactions.dart b/lib/domain_layer/usecases/user_reactions.dart index 34335de..dedac18 100644 --- a/lib/domain_layer/usecases/user_reactions.dart +++ b/lib/domain_layer/usecases/user_reactions.dart @@ -33,9 +33,16 @@ class UserReactions { if (reactions.isEmpty) { return null; } - if (reactions.first.content == "+") { - return reactions.first; + + final res = reactions.where((reaction) { + return reaction.tags.any((tag) => tag.type == "e" && tag.value == postId); + }).first; + + if (res.content != "+") { + return null; } + + return res; } Future likePost({ diff --git a/lib/presentation_layer/providers/reactions_state_provider.dart b/lib/presentation_layer/providers/reactions_state_provider.dart index e23e58f..21041df 100644 --- a/lib/presentation_layer/providers/reactions_state_provider.dart +++ b/lib/presentation_layer/providers/reactions_state_provider.dart @@ -36,7 +36,7 @@ class PostLikeNotifier extends StateNotifier { Future _initializeLikeState() async { final isLiked = await _userReactions.isPostSelfLiked(postId: _postId); - state = PostLikeState(isLiked: isLiked, isLoading: false); + state = state.copyWith(isLiked: isLiked, isLoading: false); } Future toggleLike() async { @@ -46,7 +46,7 @@ class PostLikeNotifier extends StateNotifier { try { if (state.isLiked) { - await _userReactions.deleteReaction(postId: _postId); + _userReactions.deleteReaction(postId: _postId); } else { await _userReactions.likePost( pubkeyOfEventAuthor: _postAuthorPubkey,