Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filtering to the reports data in the Focus mode switch logic #34624

Merged
merged 8 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading