Skip to content

Commit

Permalink
fix: CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-kreios committed Dec 31, 2024
1 parent 8ee4c98 commit ed88894
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserMetadataEntity>().toList();
final slivers = [
Expand Down
15 changes: 10 additions & 5 deletions lib/app/features/chat/providers/user_chat_relays_provider.c.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ Future<UserChatRelaysEntity?> userChatRelays(Ref ref, String pubkey) async {
);
}

@riverpod
class UserChatRelaysManager extends _$UserChatRelaysManager {
@override
FutureOr<void> 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<void> set() async {
Future<void> sync() async {
final pubkey = ref.watch(currentPubkeySelectorProvider);
if (pubkey == null) {
throw UserMasterPubkeyNotFoundException();
Expand All @@ -71,3 +71,8 @@ class UserChatRelaysManager extends _$UserChatRelaysManager {
ref.invalidate(userChatRelaysProvider(pubkey));
}
}

@riverpod
UserChatRelaysManager userChatRelaysManager(Ref ref) {
return UserChatRelaysManager(ref);
}
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,8 +11,10 @@ import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'users_data_source_provider.c.g.dart';

@riverpod
List<EntitiesDataSource> usersDataSource(Ref ref) {
Future<List<EntitiesDataSource>> usersDataSource(Ref ref) async {
final searchText = ref.watch(usersSearchTextProvider);

await ref.debounce();
return [
EntitiesDataSource(
actionSource: const ActionSourceIndexers(),
Expand Down
6 changes: 1 addition & 5 deletions lib/app/router/main_tabs/main_tab_navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
Expand Down

0 comments on commit ed88894

Please sign in to comment.