Skip to content

Commit

Permalink
Merge pull request #34624 from Expensify/marcaaron-fixReportCount
Browse files Browse the repository at this point in the history
Add filtering to the reports data in the Focus mode switch logic
  • Loading branch information
cristipaval authored Jan 26, 2024
2 parents d261165 + 30ef139 commit feb516a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4486,6 +4486,36 @@ function isGroupChat(report: OnyxEntry<Report>): boolean {
);
}

/**
* Assume any report without a reportID is unusable.
*/
function isValidReport(report?: OnyxEntry<Report>): boolean {
return Boolean(report?.reportID);
}

/**
* Check to see if we are a participant of this report.
*/
function isReportParticipant(accountID: number, report: OnyxEntry<Report>): boolean {
if (!accountID) {
return false;
}

// If we have a DM AND the accountID we are checking is the current user THEN we won't find them as a participant and must assume they are a participant
if (isDM(report) && accountID === currentUserAccountID) {
return true;
}

const possibleAccountIDs = report?.participantAccountIDs ?? [];
if (report?.ownerAccountID) {
possibleAccountIDs.push(report?.ownerAccountID);
}
if (report?.managerID) {
possibleAccountIDs.push(report?.managerID);
}
return possibleAccountIDs.includes(accountID);
}

function shouldUseFullTitleToDisplay(report: OnyxEntry<Report>): boolean {
return isMoneyRequestReport(report) || isPolicyExpenseChat(report) || isChatRoom(report) || isChatThread(report) || isTaskReport(report);
}
Expand Down Expand Up @@ -4809,6 +4839,8 @@ export {
shouldDisableThread,
doesReportBelongToWorkspace,
getChildReportNotificationPreference,
isReportParticipant,
isValidReport,
isReportFieldOfTypeTitle,
};

Expand Down
17 changes: 16 additions & 1 deletion src/libs/actions/PriorityMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {OnyxCollection} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as CollectionUtils from '@libs/CollectionUtils';
import Log from '@libs/Log';
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report} from '@src/types/onyx';
Expand Down Expand Up @@ -120,7 +121,21 @@ function tryFocusModeUpdate() {
return;
}

const reportCount = Object.keys(allReports ?? {}).length;
const validReports = [];
Object.keys(allReports ?? {}).forEach((key) => {
const report = allReports?.[key];
if (!report) {
return;
}

if (!ReportUtils.isValidReport(report) || !ReportUtils.isReportParticipant(currentUserAccountID ?? 0, report)) {
return;
}

validReports.push(report);
});

const reportCount = validReports.length;
if (reportCount < CONST.REPORT.MAX_COUNT_BEFORE_FOCUS_UPDATE) {
Log.info('Not switching user to optimized focus mode as they do not have enough reports', false, {reportCount});
return;
Expand Down

0 comments on commit feb516a

Please sign in to comment.