@@ -8,6 +8,7 @@ import CONST from '../../CONST';
8
8
import NetworkConnection from '../NetworkConnection' ;
9
9
import * as API from '../API' ;
10
10
import NameValuePair from './NameValuePair' ;
11
+ import * as ReportUtils from '../reportUtils' ;
11
12
import * as OptionsListUtils from '../OptionsListUtils' ;
12
13
import Growl from '../Growl' ;
13
14
import * as Localize from '../Localize' ;
@@ -145,7 +146,6 @@ function fetchPersonalDetails() {
145
146
* Get personal details from report participants.
146
147
*
147
148
* @param {Object } reports
148
- * @returns {Promise }
149
149
*/
150
150
function getFromReportParticipants ( reports ) {
151
151
const participantEmails = _ . chain ( reports )
@@ -155,10 +155,10 @@ function getFromReportParticipants(reports) {
155
155
. value ( ) ;
156
156
157
157
if ( participantEmails . length === 0 ) {
158
- return Promise . resolve ( { } ) ;
158
+ return ;
159
159
}
160
160
161
- return API . PersonalDetails_GetForEmails ( { emailList : participantEmails . join ( ',' ) } )
161
+ API . PersonalDetails_GetForEmails ( { emailList : participantEmails . join ( ',' ) } )
162
162
. then ( ( data ) => {
163
163
const existingDetails = _ . pick ( data , participantEmails ) ;
164
164
@@ -173,7 +173,36 @@ function getFromReportParticipants(reports) {
173
173
174
174
const formattedPersonalDetails = formatPersonalDetails ( details ) ;
175
175
Onyx . merge ( ONYXKEYS . PERSONAL_DETAILS , formattedPersonalDetails ) ;
176
- return details ;
176
+
177
+ // The personalDetails of the participants contain their avatar images. Here we'll go over each
178
+ // report and based on the participants we'll link up their avatars to report icons. This will
179
+ // skip over default rooms which aren't named by participants.
180
+ const reportsToUpdate = { } ;
181
+ _ . each ( reports , ( report ) => {
182
+ if ( report . participants . length <= 0 && ! ReportUtils . isChatRoom ( report ) ) {
183
+ return ;
184
+ }
185
+
186
+ const avatars = OptionsListUtils . getReportIcons ( report , details ) ;
187
+ const reportName = ReportUtils . isChatRoom ( report )
188
+ ? report . reportName
189
+ : _ . chain ( report . participants )
190
+ . filter ( participant => participant !== currentUserEmail )
191
+ . map ( participant => lodashGet (
192
+ formattedPersonalDetails ,
193
+ [ participant , 'displayName' ] ,
194
+ participant ,
195
+ ) )
196
+ . value ( )
197
+ . join ( ', ' ) ;
198
+
199
+ reportsToUpdate [ `${ ONYXKEYS . COLLECTION . REPORT } ${ report . reportID } ` ] = { icons : avatars , reportName} ;
200
+ } ) ;
201
+
202
+ // We use mergeCollection such that it updates ONYXKEYS.COLLECTION.REPORT in one go.
203
+ // Any withOnyx subscribers to this key will also receive the complete updated props just once
204
+ // than updating props for each report and re-rendering had merge been used.
205
+ Onyx . mergeCollection ( ONYXKEYS . COLLECTION . REPORT , reportsToUpdate ) ;
177
206
} ) ;
178
207
}
179
208
0 commit comments