Skip to content

Commit

Permalink
follow state
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-lox committed Oct 30, 2024
1 parent f38c1f6 commit 47892e3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
18 changes: 12 additions & 6 deletions lib/data_layer/repositories/follow_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,22 @@ class FollowRepositoryImpl implements FollowRepository {
}

@override
Future<void> followUser(String npub) async {
final newContactList =
Future<ContactList?> followUser(String npub) async {
final ndk_entities.ContactList newContactList =
await dartNdkSource.dartNdk.follows.broadcastAddContact(npub);
print(newContactList.contacts);

return ContactListModel.fromNdk(newContactList);
}

@override
Future<void> unfollowUser(String npub) async {
final newContactList =
Future<ContactList?> unfollowUser(String npub) async {
final ndk_entities.ContactList? newContactList =
await dartNdkSource.dartNdk.follows.broadcastRemoveContact(npub);
print(newContactList?.contacts);

if (newContactList == null) {
return null;
}

return ContactListModel.fromNdk(newContactList);
}
}
4 changes: 2 additions & 2 deletions lib/domain_layer/repositories/follow_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'package:camelus/domain_layer/entities/contact_list.dart';
abstract class FollowRepository {
FollowRepository();

Future<void> followUser(String npub);
Future<ContactList?> followUser(String npub);

Future<void> unfollowUser(String npub);
Future<ContactList?> unfollowUser(String npub);

Future<void> setFollowing(ContactList contactList);

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 @@ -19,11 +19,11 @@ class Follow {
}
}

Future<void> followUser(String npub) async {
Future<ContactList?> followUser(String npub) async {
return followRepository.followUser(npub);
}

Future<void> unfollowUser(String npub) async {
Future<ContactList?> unfollowUser(String npub) async {
return followRepository.unfollowUser(npub);
}

Expand Down
14 changes: 10 additions & 4 deletions lib/presentation_layer/routes/nostr/profile/follower_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,24 @@ class FollowerPage extends ConsumerStatefulWidget {

class _FollowerPageState extends ConsumerState<FollowerPage> {
/// follow Change - true to add, false to remove
void _changeFollowing(
bool followChange, String pubkey, ContactList currentOwnContacts) async {
Future<void> _changeFollowing(
bool followChange,
String pubkey,
ContactList currentOwnContacts,
) async {
final followService = ref.read(followingProvider);
List<String> newContacts = [...currentOwnContacts.contacts];

if (followChange) {
newContacts.add(pubkey);
followService.followUser(pubkey);
await followService.followUser(pubkey);
} else {
newContacts.removeWhere((element) => element == pubkey);
followService.unfollowUser(pubkey);
await followService.unfollowUser(pubkey);
}
setState(() {
currentOwnContacts.contacts = newContacts;
});
}

@override
Expand Down

0 comments on commit 47892e3

Please sign in to comment.