Skip to content

Commit

Permalink
use cache for deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-lox committed Dec 12, 2024
1 parent eb72381 commit 4552df3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/data_layer/repositories/note_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class NoteRepositoryImpl implements NoteRepository {
Future<List<NostrNote>> getReactions({
required String postId,
required List<String> authors,
bool useCache = false,
}) async {
ndk.Filter filter = ndk.Filter(
eTags: [postId],
Expand All @@ -248,8 +249,8 @@ class NoteRepositoryImpl implements NoteRepository {
timeout: Duration(seconds: 5),
filters: [filter],
name: 'getReactions-${postId.substring(5, 10)}-',
cacheRead: false,
cacheWrite: false,
cacheRead: useCache,
cacheWrite: useCache,
);

final events = await response.future;
Expand Down
1 change: 1 addition & 0 deletions lib/domain_layer/repositories/note_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ abstract class NoteRepository {
Future<List<NostrNote>> getReactions({
required String postId,
required List<String> authors,
bool useCache = false,
});

Future<List<NostrNote>> getReposts({
Expand Down
12 changes: 7 additions & 5 deletions lib/domain_layer/usecases/user_reactions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ class UserReactions {
Future<NostrNote?> isPostLiked({
required String likedByPubkey,
required String postId,
bool useCache = false,
}) async {
final reactions = await _noteRepository.getReactions(
postId: postId,
authors: [likedByPubkey],
);
postId: postId, authors: [likedByPubkey], useCache: useCache);
if (reactions.isEmpty) {
return null;
}
Expand Down Expand Up @@ -74,8 +73,11 @@ class UserReactions {
}

// get the reaction to delete
final reaction =
await isPostLiked(likedByPubkey: selfPubkey!, postId: postId);
final reaction = await isPostLiked(
likedByPubkey: selfPubkey!,
postId: postId,
useCache: true,
);
if (reaction == null) {
throw Exception("Reaction not found");
}
Expand Down

0 comments on commit 4552df3

Please sign in to comment.