Skip to content

Commit

Permalink
metadata rpository
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-lox committed Oct 24, 2024
1 parent 80eb0a1 commit d7cec82
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
29 changes: 29 additions & 0 deletions lib/data_layer/repositories/metadata_repository_impl.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:ndk/entities.dart' as ndk_entities;
import 'package:ndk/ndk.dart' as ndk;

import '../../domain_layer/entities/user_metadata.dart';
import '../../domain_layer/repositories/metadata_repository.dart';
import '../data_sources/dart_ndk_source.dart';
import '../models/user_metadata_model.dart';

class MetadataRepositoryImpl implements MetadataRepository {
final DartNdkSource dartNdkSource;
final ndk.EventVerifier eventVerifier;

MetadataRepositoryImpl({
required this.dartNdkSource,
required this.eventVerifier,
});

@override
Stream<UserMetadata> getMetadataByPubkey(String pubkey) {
final myMetadata = dartNdkSource.dartNdk.metadata.loadMetadata(pubkey);

final Stream<ndk_entities.Metadata?> myMetadataStream =
myMetadata.asStream();

return myMetadataStream.where((event) => event != null).map(
(event) => UserMetadataModel.fromNDKMetadata(event!),
);
}
}
5 changes: 5 additions & 0 deletions lib/domain_layer/repositories/metadata_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import '../entities/user_metadata.dart';

abstract class MetadataRepository {
Stream<UserMetadata> getMetadataByPubkey(String pubkey);
}
5 changes: 1 addition & 4 deletions lib/domain_layer/repositories/note_repository.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import 'package:camelus/domain_layer/entities/nostr_note.dart';
import 'package:camelus/domain_layer/entities/user_metadata.dart';
import '../entities/nostr_note.dart';

abstract class NoteRepository {
Stream<NostrNote> getAllNotes();

Stream<NostrNote> getTextNote(String noteId);

Stream<UserMetadata> getMetadataByPubkey(String pubkey);

Stream<NostrNote> getTextNotesByAuthors({
required List<String> authors,
required String requestId,
Expand Down
8 changes: 4 additions & 4 deletions lib/domain_layer/usecases/get_user_metadata.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import '../entities/user_metadata.dart';
import '../repositories/note_repository.dart';
import '../repositories/metadata_repository.dart';

class GetUserMetadata {
final NoteRepository _noteRepository;
final MetadataRepository _metadataRepository;

GetUserMetadata(this._noteRepository);
GetUserMetadata(this._metadataRepository);

Stream<UserMetadata> getMetadataByPubkey(String pubkey) {
return _noteRepository.getMetadataByPubkey(pubkey);
return _metadataRepository.getMetadataByPubkey(pubkey);
}
}
17 changes: 9 additions & 8 deletions lib/presentation_layer/providers/metadata_provider.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import 'package:camelus/data_layer/data_sources/dart_ndk_source.dart';
import 'package:camelus/data_layer/repositories/note_repository_impl.dart';
import 'package:camelus/domain_layer/repositories/note_repository.dart';
import 'package:camelus/domain_layer/usecases/get_user_metadata.dart';
import 'package:camelus/presentation_layer/providers/event_verifier.dart';
import 'package:camelus/presentation_layer/providers/ndk_provider.dart';
import 'package:riverpod/riverpod.dart';

import '../../data_layer/data_sources/dart_ndk_source.dart';
import '../../data_layer/repositories/metadata_repository_impl.dart';
import '../../domain_layer/repositories/metadata_repository.dart';
import '../../domain_layer/usecases/get_user_metadata.dart';
import 'event_verifier.dart';
import 'ndk_provider.dart';

final metadataProvider = Provider<GetUserMetadata>((ref) {
final ndk = ref.watch(ndkProvider);

final eventVerifier = ref.watch(eventVerifierProvider);

final DartNdkSource dartNdkSource = DartNdkSource(ndk);

final NoteRepository noteRepository = NoteRepositoryImpl(
final MetadataRepository metadataRepository = MetadataRepositoryImpl(
dartNdkSource: dartNdkSource,
eventVerifier: eventVerifier,
);

final GetUserMetadata getUserMetadata = GetUserMetadata(noteRepository);
final GetUserMetadata getUserMetadata = GetUserMetadata(metadataRepository);

return getUserMetadata;
});

0 comments on commit d7cec82

Please sign in to comment.