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

show #admins room only when there is value #45048

Merged
21 changes: 20 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4655,7 +4655,7 @@ function buildOptimisticChatReport(
type: CONST.REPORT.TYPE.CHAT,
chatType,
isOwnPolicyExpenseChat,
isPinned: reportName === CONST.REPORT.WORKSPACE_CHAT_ROOMS.ADMINS || isNewlyCreatedWorkspaceChat,
isPinned: isNewlyCreatedWorkspaceChat,
lastActorAccountID: 0,
lastMessageTranslationKey: '',
lastMessageHtml: '',
Expand Down Expand Up @@ -5425,6 +5425,20 @@ function hasWarningTypeViolations(reportID: string, transactionViolations: OnyxC
return transactions.some((transaction) => TransactionUtils.hasWarningTypeViolation(transaction.transactionID, transactionViolations));
}

/**
* Checks if #admins room chan be shown
* We show #admin rooms when a) More than one admin exists or b) There exists policy audit log for review.
*/
function shouldAdminsRoomBeVisible(report: OnyxEntry<Report>): boolean {
const accountIDs = Object.entries(report?.participants ?? {}).map(([accountID]) => Number(accountID));
const adminAccounts = PersonalDetailsUtils.getLoginsByAccountIDs(accountIDs).filter((login) => !PolicyUtils.isExpensifyTeam(login));
const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(report?.reportID ?? '');
if ((lastVisibleAction ? ReportActionsUtils.isCreatedAction(lastVisibleAction) : report?.lastActionType === CONST.REPORT.ACTIONS.TYPE.CREATED) && adminAccounts.length <= 1) {
return false;
}
return true;
}

/**
* Takes several pieces of data from Onyx and evaluates if a report should be shown in the option list (either when searching
* for reports or the reports shown in the LHN).
Expand Down Expand Up @@ -5537,6 +5551,11 @@ function shouldReportBeInOptionList({
return false;
}

// Show #admins room only when it has some value to the user.
if (isAdminRoom(report) && !shouldAdminsRoomBeVisible(report)) {
return false;
}

// Include reports that have errors from trying to add a workspace
// If we excluded it, then the red-brock-road pattern wouldn't work for the user to resolve the error
if (report.errorFields?.addWorkspaceRoom) {
Expand Down
Loading