Skip to content

Commit

Permalink
Merge pull request #4141 from Expensify/amal-participants-full-name-c…
Browse files Browse the repository at this point in the history
…heck

Don't check participants' whole names in default rooms
  • Loading branch information
thienlnam authored Jul 20, 2021
2 parents da89c93 + 3bae549 commit ff9b55b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ SPEC CHECKSUMS:
DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de
EXHaptics: 337c160c148baa6f0e7166249f368965906e346b
FBLazyVector: 7b423f9e248eae65987838148c36eec1dbfe0b53
FBReactNativeSpec: e564123bce1111e84dc7aa0765fb1175f0c48aa0
FBReactNativeSpec: d65967936e86fe0fe6cca5c0125c237636868d4a
Firebase: c23a36d9e4cdf7877dfcba8dd0c58add66358999
FirebaseAnalytics: 3bb096873ee0d7fa4b6c70f5e9166b6da413cc7f
FirebaseCore: d3a978a3cfa3240bf7e4ba7d137fdf5b22b628ec
Expand Down
13 changes: 7 additions & 6 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,18 @@ function createOption(personalDetailList, report, draftComments, {
* @param {String} searchValue
* @param {String} searchText
* @param {Set<String>} [participantNames]
* @param {Boolean} isDefaultChatRoom
* @returns {Boolean}
*/
function isSearchStringMatch(searchValue, searchText, participantNames = new Set()) {
function isSearchStringMatch(searchValue, searchText, participantNames = new Set(), isDefaultChatRoom = false) {
const searchWords = searchValue
.replace(/,/g, ' ')
.split(' ')
.map(word => word.trim());
return _.every(searchWords, (word) => {
const matchRegex = new RegExp(Str.escapeForRegExp(word), 'i');
const valueToSearch = searchText && searchText.replace(new RegExp(/&nbsp;/g), '');
return matchRegex.test(valueToSearch) || participantNames.has(word);
return matchRegex.test(valueToSearch) || (!isDefaultChatRoom && participantNames.has(word));
});
}

Expand Down Expand Up @@ -400,9 +401,9 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, {
}

// Finally check to see if this option is a match for the provided search string if we have one
const {searchText, participantsList} = reportOption;
const {searchText, participantsList, isDefaultChatRoom} = reportOption;
const participantNames = getParticipantNames(participantsList);
if (searchValue && !isSearchStringMatch(searchValue, searchText, participantNames)) {
if (searchValue && !isSearchStringMatch(searchValue, searchText, participantNames, isDefaultChatRoom)) {
continue;
}

Expand Down Expand Up @@ -449,9 +450,9 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, {
))) {
return;
}
const {searchText, participantsList} = personalDetailOption;
const {searchText, participantsList, isDefaultChatRoom} = personalDetailOption;
const participantNames = getParticipantNames(participantsList);
if (searchValue && !isSearchStringMatch(searchValue, searchText, participantNames)) {
if (searchValue && !isSearchStringMatch(searchValue, searchText, participantNames, isDefaultChatRoom)) {
return;
}
personalDetailsOptions.push(personalDetailOption);
Expand Down

0 comments on commit ff9b55b

Please sign in to comment.