diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index dc2ecd02813d..655cb6600fd0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -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: '', @@ -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): 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). @@ -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) {