|
1 | 1 | import 'package:flutter_riverpod/flutter_riverpod.dart'; |
2 | 2 | import 'package:whitenoise/config/providers/active_pubkey_provider.dart'; |
3 | | -import 'package:whitenoise/config/providers/user_profile_data_provider.dart'; |
4 | | -import 'package:whitenoise/domain/models/contact_model.dart'; |
| 3 | +import 'package:whitenoise/config/providers/user_profile_provider.dart'; |
5 | 4 | import 'package:whitenoise/domain/models/message_model.dart'; |
6 | 5 | import 'package:whitenoise/domain/models/user_model.dart' as domain_user; |
| 6 | +import 'package:whitenoise/domain/models/user_profile.dart'; |
7 | 7 | import 'package:whitenoise/src/rust/api/groups.dart' as groups_api; |
8 | 8 | import 'package:whitenoise/src/rust/api/messages.dart' |
9 | 9 | show ChatMessage, fetchAggregatedMessagesForGroup; |
@@ -92,73 +92,73 @@ class GroupMessagesNotifier extends FamilyNotifier<GroupMessagesState, String> { |
92 | 92 | if (activePubkey == null || activePubkey.isEmpty) { |
93 | 93 | return {}; |
94 | 94 | } |
95 | | - final groupContacts = await _fetchGroupUsersProfileData(activePubkey); |
96 | | - final domainUsersMap = _mapContactModelsToDomainUsers( |
| 95 | + final groupUserProfiles = await _fetchGroupUserProfiles(activePubkey); |
| 96 | + final domainUsersMap = _mapUserProfilesToDomainUsers( |
97 | 97 | activePubkey: activePubkey, |
98 | | - contacts: groupContacts, |
| 98 | + userProfiles: groupUserProfiles, |
99 | 99 | ); |
100 | 100 | return domainUsersMap; |
101 | 101 | } |
102 | 102 |
|
103 | | - Future<List<MapEntry<String, ContactModel>>> _fetchUsersProfileData( |
| 103 | + Future<List<MapEntry<String, UserProfile>>> _fetchUserProfiles( |
104 | 104 | List<String> pubkeys, |
105 | 105 | ) async { |
106 | | - final userProfileDataNotifier = ref.read(userProfileDataProvider.notifier); |
| 106 | + final userProfileNotifier = ref.read(userProfileProvider.notifier); |
107 | 107 | final userFutures = pubkeys.map( |
108 | | - (pubkey) => userProfileDataNotifier |
109 | | - .getUserProfileData(pubkey) |
110 | | - .then((contact) => MapEntry(pubkey, contact)), |
| 108 | + (pubkey) => userProfileNotifier |
| 109 | + .getUserProfile(pubkey) |
| 110 | + .then((userProfile) => MapEntry(pubkey, userProfile)), |
111 | 111 | ); |
112 | 112 | final usersProfileData = await Future.wait(userFutures); |
113 | 113 | return usersProfileData; |
114 | 114 | } |
115 | 115 |
|
116 | | - Future<List<MapEntry<String, ContactModel>>> _fetchGroupUsersProfileData( |
| 116 | + Future<List<MapEntry<String, UserProfile>>> _fetchGroupUserProfiles( |
117 | 117 | String activePubkey, |
118 | 118 | ) async { |
119 | 119 | final groupMembersPubkeys = await _groupMembers( |
120 | 120 | pubkey: activePubkey, |
121 | 121 | groupId: state.groupId, |
122 | 122 | ); |
123 | | - final groupMembersUserProfileData = await _fetchUsersProfileData(groupMembersPubkeys); |
124 | | - return groupMembersUserProfileData; |
| 123 | + final groupMembersUserProfile = await _fetchUserProfiles(groupMembersPubkeys); |
| 124 | + return groupMembersUserProfile; |
125 | 125 | } |
126 | 126 |
|
127 | | - Map<String, domain_user.User> _mapContactModelsToDomainUsers({ |
| 127 | + Map<String, domain_user.User> _mapUserProfilesToDomainUsers({ |
128 | 128 | required String activePubkey, |
129 | | - required List<MapEntry<String, ContactModel>> contacts, |
| 129 | + required List<MapEntry<String, UserProfile>> userProfiles, |
130 | 130 | }) { |
131 | 131 | return Map<String, domain_user.User>.fromEntries( |
132 | | - contacts.map( |
| 132 | + userProfiles.map( |
133 | 133 | (entry) => MapEntry( |
134 | 134 | entry.key, |
135 | | - _contactModelToDomainUser(activePubkey: activePubkey, contact: entry.value), |
| 135 | + _userProfileToDomainUser(activePubkey: activePubkey, userProfile: entry.value), |
136 | 136 | ), |
137 | 137 | ), |
138 | 138 | ); |
139 | 139 | } |
140 | 140 |
|
141 | 141 | String _getDisplayName({ |
142 | 142 | required String activePubkey, |
143 | | - required ContactModel contact, |
| 143 | + required UserProfile userProfile, |
144 | 144 | }) { |
145 | | - if (_isMe(myPubkey: activePubkey, otherPubkey: contact.publicKey)) { |
| 145 | + if (_isMe(myPubkey: activePubkey, otherPubkey: userProfile.publicKey)) { |
146 | 146 | return 'You'; |
147 | 147 | } else { |
148 | | - return contact.displayName; |
| 148 | + return userProfile.displayName; |
149 | 149 | } |
150 | 150 | } |
151 | 151 |
|
152 | | - domain_user.User _contactModelToDomainUser({ |
| 152 | + domain_user.User _userProfileToDomainUser({ |
153 | 153 | required String activePubkey, |
154 | | - required ContactModel contact, |
| 154 | + required UserProfile userProfile, |
155 | 155 | }) { |
156 | 156 | return domain_user.User( |
157 | | - id: contact.publicKey, |
158 | | - displayName: _getDisplayName(activePubkey: activePubkey, contact: contact), |
159 | | - nip05: contact.nip05 ?? '', |
160 | | - publicKey: contact.publicKey, |
161 | | - imagePath: contact.imagePath, |
| 157 | + id: userProfile.publicKey, |
| 158 | + displayName: _getDisplayName(activePubkey: activePubkey, userProfile: userProfile), |
| 159 | + nip05: userProfile.nip05 ?? '', |
| 160 | + publicKey: userProfile.publicKey, |
| 161 | + imagePath: userProfile.imagePath, |
162 | 162 | ); |
163 | 163 | } |
164 | 164 | } |
|
0 commit comments