Skip to content

Commit

Permalink
Merge pull request #7631 from Expensify/revert-7453-sn_bug-report-icons
Browse files Browse the repository at this point in the history
Revert "Separate report name and icon configuration from personal details"

(cherry picked from commit b55663a)
  • Loading branch information
luacmartins authored and OSBotify committed Feb 8, 2022
1 parent 423a1ac commit e2b43cb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 47 deletions.
37 changes: 33 additions & 4 deletions src/libs/actions/PersonalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CONST from '../../CONST';
import NetworkConnection from '../NetworkConnection';
import * as API from '../API';
import NameValuePair from './NameValuePair';
import * as ReportUtils from '../reportUtils';
import * as OptionsListUtils from '../OptionsListUtils';
import Growl from '../Growl';
import * as Localize from '../Localize';
Expand Down Expand Up @@ -145,7 +146,6 @@ function fetchPersonalDetails() {
* Get personal details from report participants.
*
* @param {Object} reports
* @returns {Promise}
*/
function getFromReportParticipants(reports) {
const participantEmails = _.chain(reports)
Expand All @@ -155,10 +155,10 @@ function getFromReportParticipants(reports) {
.value();

if (participantEmails.length === 0) {
return Promise.resolve({});
return;
}

return API.PersonalDetails_GetForEmails({emailList: participantEmails.join(',')})
API.PersonalDetails_GetForEmails({emailList: participantEmails.join(',')})
.then((data) => {
const existingDetails = _.pick(data, participantEmails);

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

const formattedPersonalDetails = formatPersonalDetails(details);
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS, formattedPersonalDetails);
return details;

// The personalDetails of the participants contain their avatar images. Here we'll go over each
// report and based on the participants we'll link up their avatars to report icons. This will
// skip over default rooms which aren't named by participants.
const reportsToUpdate = {};
_.each(reports, (report) => {
if (report.participants.length <= 0 && !ReportUtils.isChatRoom(report)) {
return;
}

const avatars = OptionsListUtils.getReportIcons(report, details);
const reportName = ReportUtils.isChatRoom(report)
? report.reportName
: _.chain(report.participants)
.filter(participant => participant !== currentUserEmail)
.map(participant => lodashGet(
formattedPersonalDetails,
[participant, 'displayName'],
participant,
))
.value()
.join(', ');

reportsToUpdate[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`] = {icons: avatars, reportName};
});

// We use mergeCollection such that it updates ONYXKEYS.COLLECTION.REPORT in one go.
// Any withOnyx subscribers to this key will also receive the complete updated props just once
// than updating props for each report and re-rendering had merge been used.
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, reportsToUpdate);
});
}

Expand Down
44 changes: 1 addition & 43 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,45 +320,6 @@ function fetchIOUReportID(debtorEmail) {
});
}

function configureReportNameAndIcons(reports, details) {
// The personalDetails of the participants contain their avatar images. Here we'll go over each
// report and based on the participants we'll link up their avatars to report icons. This will
// skip over default rooms which aren't named by participants.

const reportsToUpdate = {};
_.each(reports, (report) => {
if (report.participants.length <= 0 && !ReportUtils.isChatRoom(report)) {
return;
}
const isChatRoom = ReportUtils.isChatRoom(report);

// Chat rooms have a specific avatar so we can return any non-empty array but for 1:1 chats and group chats
// avatars are extracted from avatars of the participants.
const avatars = isChatRoom ? [''] : OptionsListUtils.getReportIcons(report, details);

// ReportName is already present in report for chatrooms but for 1:1 chats and group chats
// reportName is extracted from displayNames of the participants.
const reportName = isChatRoom
? report.reportName
: _.chain(report.participants)
.filter(participant => participant !== currentUserEmail)
.map(participant => lodashGet(
PersonalDetails.formatPersonalDetails(details),
[participant, 'displayName'],
participant,
))
.value()
.join(', ');

reportsToUpdate[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`] = {icons: avatars, reportName};
});

// We use mergeCollection such that it updates ONYXKEYS.COLLECTION.REPORT in one go.
// Any withOnyx subscribers to this key will also receive the complete updated props just once
// than updating props for each report and re-rendering had merge been used.
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, reportsToUpdate);
}

/**
* Fetches chat reports when provided a list of chat report IDs.
* If the shouldRedirectIfInaccessible flag is set, we redirect to the Concierge chat
Expand Down Expand Up @@ -439,11 +400,8 @@ function fetchChatReportsByIDs(chatList, shouldRedirectIfInaccessible = false) {
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT_IOUS, reportIOUData);
Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, simplifiedReports);

const simplifiedReportsList = _.values(simplifiedReports);

// Fetch the personal details if there are any
PersonalDetails.getFromReportParticipants(simplifiedReportsList)
.then(details => configureReportNameAndIcons(simplifiedReportsList, details));
PersonalDetails.getFromReportParticipants(_.values(simplifiedReports));
return fetchedReports;
})
.catch((err) => {
Expand Down

0 comments on commit e2b43cb

Please sign in to comment.