Skip to content

Commit 8b8e828

Browse files
chiragsalianOSBotify
authored andcommitted
Merge pull request #7426 from Expensify/revert-7367-sn-bug_report_name_icon
Revert "Separate report name and icon configuration from personal details" (cherry picked from commit 38b99b1)
1 parent 9e94074 commit 8b8e828

File tree

2 files changed

+34
-42
lines changed

2 files changed

+34
-42
lines changed

src/libs/actions/PersonalDetails.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CONST from '../../CONST';
88
import NetworkConnection from '../NetworkConnection';
99
import * as API from '../API';
1010
import NameValuePair from './NameValuePair';
11+
import * as ReportUtils from '../reportUtils';
1112
import * as OptionsListUtils from '../OptionsListUtils';
1213
import Growl from '../Growl';
1314
import * as Localize from '../Localize';
@@ -145,7 +146,6 @@ function fetchPersonalDetails() {
145146
* Get personal details from report participants.
146147
*
147148
* @param {Object} reports
148-
* @returns {Promise}
149149
*/
150150
function getFromReportParticipants(reports) {
151151
const participantEmails = _.chain(reports)
@@ -155,10 +155,10 @@ function getFromReportParticipants(reports) {
155155
.value();
156156

157157
if (participantEmails.length === 0) {
158-
return Promise.resolve({});
158+
return;
159159
}
160160

161-
return API.PersonalDetails_GetForEmails({emailList: participantEmails.join(',')})
161+
API.PersonalDetails_GetForEmails({emailList: participantEmails.join(',')})
162162
.then((data) => {
163163
const existingDetails = _.pick(data, participantEmails);
164164

@@ -173,7 +173,36 @@ function getFromReportParticipants(reports) {
173173

174174
const formattedPersonalDetails = formatPersonalDetails(details);
175175
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);
177206
});
178207
}
179208

src/libs/actions/Report.js

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -320,39 +320,6 @@ function fetchIOUReportID(debtorEmail) {
320320
});
321321
}
322322

323-
function configureReportNameAndIcon(reports, details) {
324-
// The personalDetails of the participants contain their avatar images. Here we'll go over each
325-
// report and based on the participants we'll link up their avatars to report icons. This will
326-
// skip over default rooms which aren't named by participants.
327-
328-
const reportsToUpdate = {};
329-
_.each(reports, (report) => {
330-
if (report.participants.length <= 0 && !ReportUtils.isChatRoom(report)) {
331-
return;
332-
}
333-
334-
const avatars = ReportUtils.isChatRoom(report) ? (['']) : OptionsListUtils.getReportIcons(report, details);
335-
const reportName = ReportUtils.isChatRoom(report)
336-
? report.reportName
337-
: _.chain(report.participants)
338-
.filter(participant => participant !== currentUserEmail)
339-
.map(participant => lodashGet(
340-
details,
341-
[participant, 'displayName'],
342-
participant,
343-
))
344-
.value()
345-
.join(', ');
346-
347-
reportsToUpdate[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`] = {icons: avatars, reportName};
348-
});
349-
350-
// We use mergeCollection such that it updates ONYXKEYS.COLLECTION.REPORT in one go.
351-
// Any withOnyx subscribers to this key will also receive the complete updated props just once
352-
// than updating props for each report and re-rendering had merge been used.
353-
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, reportsToUpdate);
354-
}
355-
356323
/**
357324
* Fetches chat reports when provided a list of chat report IDs.
358325
* If the shouldRedirectIfInaccessible flag is set, we redirect to the Concierge chat
@@ -433,12 +400,8 @@ function fetchChatReportsByIDs(chatList, shouldRedirectIfInaccessible = false) {
433400
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT_IOUS, reportIOUData);
434401
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, simplifiedReports);
435402

436-
const simplifiedReportsList = _.values(simplifiedReports);
437-
438403
// Fetch the personal details if there are any
439-
PersonalDetails.getFromReportParticipants(simplifiedReportsList)
440-
.then(details => configureReportNameAndIcon(simplifiedReportsList, details));
441-
404+
PersonalDetails.getFromReportParticipants(_.values(simplifiedReports));
442405
return fetchedReports;
443406
})
444407
.catch((err) => {

0 commit comments

Comments
 (0)