Skip to content

Commit

Permalink
Update comment
Browse files Browse the repository at this point in the history
Add some methods to check if the report is valid

Fix ts stuff
  • Loading branch information
marcaaron committed Jan 17, 2024
1 parent 278d04e commit 9710b71
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4317,6 +4317,29 @@ 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(report?: OnyxEntry<Report>, accountID: number): boolean {

Check failure on line 4330 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Default parameters should be last

Check failure on line 4330 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / typecheck

A required parameter cannot follow an optional parameter.
if (!accountID) {
return false;
}

// We are not the owner or the manager or a participant
if (report?.ownerAccountID !== accountID && report?.managerID !== accountID && !(report?.participantAccountIDs ?? []).includes(accountID)) {
return false;
}

return true;
}

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

export type {ExpenseOriginalMessage, OptionData, OptimisticChatReport, OptimisticCreatedReportAction};
13 changes: 12 additions & 1 deletion src/libs/actions/PriorityMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Log from '@libs/Log';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report} from '@src/types/onyx';
import * as ReportUtils from '@libs/ReportUtils';

/**
* This actions file is used to automatically switch a user into #focus mode when they exceed a certain number of reports. We do this primarily for performance reasons.
Expand Down Expand Up @@ -120,7 +121,17 @@ function tryFocusModeUpdate() {
return;
}

const reportCount = Object.keys(allReports ?? {}).length;
const validReports = [];
Object.keys(allReports ?? {}).forEach((key) => {
const report = allReports?.[key];
if (ReportUtils.isValidReport(report) || !ReportUtils.isReportParticipant(currentUserAccountID ?? 0, report)) {

Check failure on line 127 in src/libs/actions/PriorityMode.ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'number' is not assignable to parameter of type '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 9710b71

Please sign in to comment.