From e57478a4d6ac1eccbbd5889a926a2edae6ae8efc Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 27 Apr 2023 17:19:45 -0700 Subject: [PATCH] Allow navigating to public announce rooms as the initial report after signing in/signing up --- src/libs/ReportUtils.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 398cd025e598..b88df5997e38 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -257,6 +257,17 @@ function isPublicRoom(report) { return visibility === CONST.REPORT.VISIBILITY.PUBLIC || visibility === CONST.REPORT.VISIBILITY.PUBLIC_ANNOUNCE; } +/** + * Whether the provided report is a public announce room + * @param {Object} report + * @param {String} report.visibility + * @returns {Boolean} + */ +function isPublicAnnounceRoom(report) { + const visibility = lodashGet(report, 'visibility', ''); + return visibility === CONST.REPORT.VISIBILITY.PUBLIC_ANNOUNCE; +} + /** * Get the policy type from a given report * @param {Object} report @@ -288,7 +299,9 @@ function findLastAccessedReport(reports, ignoreDefaultRooms, policies, openOnAdm let sortedReports = sortReportsByLastRead(reports); if (ignoreDefaultRooms) { - sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report) + // We allow public announce rooms to show as the last accessed report since we bypass the default rooms beta for them. + // Check where ReportUtils.findLastAccessedReport is called in MainDrawerNavigator.js for more context. + sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report) || isPublicAnnounceRoom(report) || getPolicyType(report, policies) === CONST.POLICY.TYPE.FREE || hasExpensifyGuidesEmails(lodashGet(report, ['participants'], []))); } @@ -1707,7 +1720,7 @@ function canLeaveRoom(report, isPolicyMember) { || _.isEmpty(report.chatType)) { // DM chats don't have a chatType return false; } - } else if (report.visibility === CONST.REPORT.VISIBILITY.PUBLIC_ANNOUNCE && isPolicyMember) { + } else if (isPublicAnnounceRoom(report) && isPolicyMember) { return false; } return true; @@ -1758,6 +1771,7 @@ export { isArchivedRoom, isPolicyExpenseChatAdmin, isPublicRoom, + isPublicAnnounceRoom, isConciergeChatReport, isCurrentUserTheOnlyParticipant, hasAutomatedExpensifyEmails,