diff --git a/lib/app/features/chat/components/following_user_list/following_user_list.dart b/lib/app/features/chat/components/following_user_list/following_user_list.dart index d6c59a295..2be1228b6 100644 --- a/lib/app/features/chat/components/following_user_list/following_user_list.dart +++ b/lib/app/features/chat/components/following_user_list/following_user_list.dart @@ -23,15 +23,25 @@ class FollowingUsersList extends ConsumerWidget { return ListView.builder( itemBuilder: (context, index) { - final user = ref.watch(userMetadataProvider(pubkeys[index])).valueOrNull; - - return ListItem.user( - title: Text(user?.data.displayName ?? ''), - subtitle: Text(prefixUsername(username: user?.data.name ?? '', context: context)), - profilePicture: user?.data.picture, - ); + return _FollowingUserListItem(pubkey: pubkeys[index]); }, itemCount: pubkeys.length, ); } } + +class _FollowingUserListItem extends ConsumerWidget { + const _FollowingUserListItem({required this.pubkey}); + + final String pubkey; + + @override + Widget build(BuildContext context, WidgetRef ref) { + final user = ref.watch(userMetadataProvider(pubkey)).valueOrNull; + return ListItem.user( + title: Text(user?.data.displayName ?? ''), + subtitle: Text(prefixUsername(username: user?.data.name ?? '', context: context)), + profilePicture: user?.data.picture, + ); + } +} diff --git a/lib/app/features/chat/components/searched_user_list/searched_user_list.dart b/lib/app/features/chat/components/searched_user_list/searched_user_list.dart index 32842ab7b..fcbcb0d2f 100644 --- a/lib/app/features/chat/components/searched_user_list/searched_user_list.dart +++ b/lib/app/features/chat/components/searched_user_list/searched_user_list.dart @@ -15,7 +15,7 @@ class SearchedUsersList extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final dataSource = ref.watch(usersDataSourceProvider); + final dataSource = ref.watch(usersDataSourceProvider).valueOrNull; final entitiesPagedData = ref.watch(entitiesPagedDataProvider(dataSource)); final users = entitiesPagedData?.data.items?.whereType().toList(); final slivers = [ diff --git a/lib/app/features/chat/providers/user_chat_relays_provider.c.dart b/lib/app/features/chat/providers/user_chat_relays_provider.c.dart index 6a85d37fd..3ab95ef34 100644 --- a/lib/app/features/chat/providers/user_chat_relays_provider.c.dart +++ b/lib/app/features/chat/providers/user_chat_relays_provider.c.dart @@ -34,17 +34,17 @@ Future userChatRelays(Ref ref, String pubkey) async { ); } -@riverpod -class UserChatRelaysManager extends _$UserChatRelaysManager { - @override - FutureOr build() {} +class UserChatRelaysManager { + UserChatRelaysManager(this.ref); + + final Ref ref; /// /// Fetches user relays and sets them as chat relays if they differ /// If chat relays already match user relays, does nothing /// Signs and broadcasts new chat relay list if an update is needed /// - Future set() async { + Future sync() async { final pubkey = ref.watch(currentPubkeySelectorProvider); if (pubkey == null) { throw UserMasterPubkeyNotFoundException(); @@ -71,3 +71,8 @@ class UserChatRelaysManager extends _$UserChatRelaysManager { ref.invalidate(userChatRelaysProvider(pubkey)); } } + +@riverpod +UserChatRelaysManager userChatRelaysManager(Ref ref) { + return UserChatRelaysManager(ref); +} diff --git a/lib/app/features/chat/providers/users_data_source_provider.c.dart b/lib/app/features/chat/providers/users_data_source_provider.c.dart index 52c2b83f6..e2d99862d 100644 --- a/lib/app/features/chat/providers/users_data_source_provider.c.dart +++ b/lib/app/features/chat/providers/users_data_source_provider.c.dart @@ -1,6 +1,7 @@ // SPDX-License-Identifier: ice License 1.0 import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:ion/app/extensions/extensions.dart'; import 'package:ion/app/features/nostr/model/action_source.dart'; import 'package:ion/app/features/nostr/providers/entities_paged_data_provider.c.dart'; import 'package:ion/app/features/user/model/user_metadata.c.dart'; @@ -10,8 +11,10 @@ import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'users_data_source_provider.c.g.dart'; @riverpod -List usersDataSource(Ref ref) { +Future> usersDataSource(Ref ref) async { final searchText = ref.watch(usersSearchTextProvider); + + await ref.debounce(); return [ EntitiesDataSource( actionSource: const ActionSourceIndexers(), diff --git a/lib/app/router/main_tabs/main_tab_navigation.dart b/lib/app/router/main_tabs/main_tab_navigation.dart index 1d4080307..0d4d898a8 100644 --- a/lib/app/router/main_tabs/main_tab_navigation.dart +++ b/lib/app/router/main_tabs/main_tab_navigation.dart @@ -6,7 +6,6 @@ import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:ion/app/extensions/extensions.dart'; -import 'package:ion/app/features/auth/providers/auth_provider.c.dart'; import 'package:ion/app/features/chat/providers/user_chat_relays_provider.c.dart'; import 'package:ion/app/features/chat/recent_chats/providers/conversations_edit_mode_provider.c.dart'; import 'package:ion/app/features/chat/recent_chats/views/components/conversation_edit_bottom_bar/conversation_edit_bottom_bar.dart'; @@ -29,10 +28,7 @@ class MainTabNavigation extends HookConsumerWidget { final currentTab = TabItem.fromNavigationIndex(shell.currentIndex); useOnInit(() { - final pubkey = ref.watch(currentPubkeySelectorProvider); - if (pubkey != null) { - ref.read(userChatRelaysManagerProvider.notifier).set(); - } + ref.read(userChatRelaysManagerProvider).sync(); }); return Scaffold(