-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
48 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |