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 3 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
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(accountID: number, report?: OnyxEntry<Report>): boolean {
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)) {
Copy link
Contributor

@c3024 c3024 Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BE returns ownerAccountID as 0 and this check is failing for report owner
Screenshot 2024-01-23 at 12 03 53 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. In the case of a DM - you would not be in the participantAccountIDs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DMs are supposed to have an ownerAccountID of 0 that is expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the problem is that they won't be in there... have a solution one sec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if the latest commit looks better!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this gets correct valid report length,

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 @@ -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,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)) {
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