Skip to content

Commit 1b1ff04

Browse files
committed
Merge
2 parents aba0992 + 6a387b9 commit 1b1ff04

File tree

4 files changed

+90
-13
lines changed

4 files changed

+90
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
- Fixes follow/unfollow in start chat sheet
2828
- Fixes wrong relay status error when switching accounts
2929
- Fixes scroll to bototm inside of chats
30+
- Fixed profile image not showing up chatlist after login
3031

3132
### Security
3233

lib/config/providers/group_provider.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ class GroupsNotifier extends Notifier<GroupsState> {
363363
}
364364
}
365365

366-
final updatedGroupMembers = Map<String, List<domain_user.User>>.from(state.groupMembers ?? {});
366+
final updatedGroupMembers = Map<String, List<domain_user.User>>.from(
367+
state.groupMembers ?? {},
368+
);
367369
updatedGroupMembers[groupId] = members;
368370

369371
state = state.copyWith(groupMembers: updatedGroupMembers);

lib/ui/contact_list/widgets/chat_list_active_account_avatar.dart

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,106 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
33
import 'package:flutter_screenutil/flutter_screenutil.dart';
44
import 'package:go_router/go_router.dart';
55
import 'package:whitenoise/config/providers/active_account_provider.dart';
6+
import 'package:whitenoise/config/providers/user_profile_data_provider.dart';
7+
import 'package:whitenoise/domain/models/contact_model.dart';
68
import 'package:whitenoise/routing/routes.dart';
79
import 'package:whitenoise/ui/core/ui/wn_avatar.dart';
810

9-
class ChatListActiveAccountAvatar extends ConsumerWidget {
10-
const ChatListActiveAccountAvatar({super.key, this.onTap});
11+
class ChatListActiveAccountAvatar extends ConsumerStatefulWidget {
12+
const ChatListActiveAccountAvatar({
13+
super.key,
14+
this.onTap,
15+
});
1116

1217
final VoidCallback? onTap;
1318

1419
@override
15-
Widget build(BuildContext context, WidgetRef ref) {
16-
final activeAccountState = ref.watch(activeAccountProvider);
17-
final metadata = activeAccountState.value?.metadata;
18-
final currentDisplayName = metadata?.displayName ?? '';
19-
final profileImagePath = metadata?.picture ?? '';
20+
ConsumerState<ChatListActiveAccountAvatar> createState() => _ChatListActiveAccountAvatarState();
21+
}
22+
23+
class _ChatListActiveAccountAvatarState extends ConsumerState<ChatListActiveAccountAvatar> {
24+
ProviderSubscription<AsyncValue<ActiveAccountState>>? _activeAccountSubscription;
25+
ContactModel? _profileData;
26+
27+
@override
28+
void initState() {
29+
super.initState();
30+
WidgetsBinding.instance.addPostFrameCallback((_) {
31+
_loadProfileData();
32+
_activeAccountSubscription = ref.listenManual(
33+
activeAccountProvider,
34+
(previous, next) {
35+
if (next is AsyncData) {
36+
_loadProfileData();
37+
}
38+
},
39+
);
40+
});
41+
}
42+
43+
@override
44+
void dispose() {
45+
_activeAccountSubscription?.close();
46+
super.dispose();
47+
}
2048

49+
Future<void> _loadProfileData() async {
50+
try {
51+
final AsyncValue<ActiveAccountState> activeAccountState = ref.read(activeAccountProvider);
52+
final String? pubkey = activeAccountState.valueOrNull?.account?.pubkey;
53+
if (pubkey == null || pubkey.isEmpty) return;
54+
final ContactModel profileData = await ref
55+
.read(userProfileDataProvider.notifier)
56+
.getUserProfileData(pubkey);
57+
if (!mounted) return;
58+
final String? currentPubkey = ref.read(activeAccountProvider).valueOrNull?.account?.pubkey;
59+
if (currentPubkey != pubkey) return;
60+
setState(() {
61+
_profileData = profileData;
62+
});
63+
} catch (_) {
64+
if (!mounted) return;
65+
setState(() {
66+
_profileData = null;
67+
});
68+
}
69+
}
70+
71+
Widget _buildAvatar({
72+
String imageUrl = '',
73+
String? displayName,
74+
}) {
2175
return InkWell(
2276
borderRadius: BorderRadius.circular(16.r),
2377
onTap:
24-
onTap ??
78+
widget.onTap ??
2579
() {
2680
context.push(Routes.settings);
2781
},
2882
child: WnAvatar(
29-
imageUrl: profileImagePath,
30-
displayName: currentDisplayName,
83+
imageUrl: imageUrl,
84+
displayName: displayName,
3185
size: 36.r,
3286
),
3387
);
3488
}
89+
90+
@override
91+
Widget build(BuildContext context) {
92+
final activeAccountState = ref.watch(activeAccountProvider);
93+
94+
return activeAccountState.when(
95+
data: (state) {
96+
if (state.account != null && _profileData != null) {
97+
return _buildAvatar(
98+
imageUrl: _profileData?.imagePath ?? '',
99+
displayName: _profileData?.displayName,
100+
);
101+
}
102+
return _buildAvatar();
103+
},
104+
loading: () => _buildAvatar(),
105+
error: (error, stack) => _buildAvatar(),
106+
);
107+
}
35108
}

lib/utils/message_converter.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,9 @@ class MessageConverter {
560560
return await Future.microtask(() async {
561561
final userProfileNotifier = ref.read(userProfileDataProvider.notifier);
562562
final userFutures = uniquePubkeys.map(
563-
(pubkey) =>
564-
userProfileNotifier.getUserProfileData(pubkey).then((contact) => MapEntry(pubkey, contact)),
563+
(pubkey) => userProfileNotifier
564+
.getUserProfileData(pubkey)
565+
.then((contact) => MapEntry(pubkey, contact)),
565566
);
566567
final userResults = await Future.wait(userFutures);
567568
return Map<String, User>.fromEntries(

0 commit comments

Comments
 (0)