Skip to content

Commit

Permalink
use follow usecase for getContacts
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-lox committed Oct 30, 2024
1 parent 1e98867 commit d3f7cc8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 25 deletions.
25 changes: 7 additions & 18 deletions lib/data_layer/repositories/follow_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,15 @@ class FollowRepositoryImpl implements FollowRepository {
});

@override
Future<ContactList> getContacts(String npub, {int? timeout}) async {
dart_ndk.Filter filter = dart_ndk.Filter(
authors: [npub],
kinds: [ndk_entities.ContactList.KIND],
);
Future<ContactList?> getContacts(String npub, {int? timeout}) async {
final contactListNdk =
await dartNdkSource.dartNdk.follows.getContactList(npub);

final response = dartNdkSource.dartNdk.requests.query(
filters: [filter],
name: 'get_contacts',
timeout: timeout,
);
if (contactListNdk == null) {
return null;
}

final responseList = await response.stream.toList();

responseList.sort((a, b) => a.createdAt.compareTo(b.createdAt));

final ndkContactList =
ndk_entities.ContactList.fromEvent(responseList.first);

return ContactListModel.fromNdk(ndkContactList);
return ContactListModel.fromNdk(contactListNdk);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/domain_layer/repositories/follow_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class FollowRepository {

Future<bool> isFollowing(String npub);

Future<ContactList> getContacts(String npub, {int? timeout});
Future<ContactList?> getContacts(String npub, {int? timeout});

Stream<ContactList> getContactsStream(String npub);

Expand Down
4 changes: 2 additions & 2 deletions lib/domain_layer/usecases/follow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class Follow {
throw UnimplementedError();
}

Future<ContactList> getContacts(String npub, {int? timeout}) {
Future<ContactList?> getContacts(String npub, {int? timeout}) {
return followRepository.getContacts(npub, timeout: timeout);
}

Future<ContactList> getContactsSelf() {
Future<ContactList?> getContactsSelf() {
_checkSelfPubkey();
return getContacts(selfPubkey!);
}
Expand Down
12 changes: 11 additions & 1 deletion lib/domain_layer/usecases/main_feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class MainFeed {
}) async {
final contactList = await _follow.getContactsSelf();

if (contactList == null) {
log("no contact list found for $npub");
return;
}

final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
final newNotesStream = _noteRepository.getTextNotesByAuthors(
authors: contactList.contacts,
Expand Down Expand Up @@ -66,7 +71,12 @@ class MainFeed {
}) async {
// get contacts of user

final contactList = await _follow.getContacts(npub, timeout: 1);
final contactList = await _follow.getContacts(npub, timeout: 10);

if (contactList == null) {
log("no contact list found for $npub");
return;
}

final mynotesStream = _noteRepository.getTextNotesByAuthors(
authors: contactList.contacts,
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation_layer/routes/nostr/nostr_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class NostrDrawer extends ConsumerWidget {
),
Row(
children: [
FutureBuilder<ContactList>(
FutureBuilder<ContactList?>(
future: followingService.getContacts(pubkey),
builder: (context, snapshot) {
return RichText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ class _OnboardingFollowGraphState extends ConsumerState<OnboardingFollowGraph> {
(await metadataP.getMetadataByPubkey(pubkey).toList()).first;
final followInfo = await followP.getContacts(pubkey);

if (followInfo == null) {
throw Exception("followInfo is null");
}

final GraphNodeData mynode = GraphNodeData(
pubkey: pubkey,
userMetadata: metadata,
Expand Down
4 changes: 2 additions & 2 deletions lib/presentation_layer/routes/nostr/profile/profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ class _ProfilePageState extends ConsumerState<ProfilePage>
children: [
const Icon(Icons.people, color: Palette.white, size: 17),
const SizedBox(width: 5),
FutureBuilder<ContactList>(
FutureBuilder<ContactList?>(
future: followingService.getContacts(widget.pubkey),
builder: (BuildContext context,
AsyncSnapshot<ContactList> snapshot) {
AsyncSnapshot<ContactList?> snapshot) {
var contactsCountString = "";

if (snapshot.hasData) {
Expand Down

0 comments on commit d3f7cc8

Please sign in to comment.