Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperhuangg committed Apr 28, 2023
1 parent e57478a commit 57de036
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
13 changes: 11 additions & 2 deletions src/libs/Navigation/AppNavigator/MainDrawerNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const propTypes = {
type: PropTypes.string,
})),

isFirstTimeNewExpensifyUser: PropTypes.bool,

route: PropTypes.shape({
params: PropTypes.shape({
openOnAdminRoom: PropTypes.bool,
Expand All @@ -48,6 +50,7 @@ const defaultProps = {
reports: {},
betas: [],
policies: {},
isFirstTimeNewExpensifyUser: false,
};

/**
Expand All @@ -56,11 +59,12 @@ const defaultProps = {
* @param {Object} reports
* @param {Boolean} [ignoreDefaultRooms]
* @param {Object} policies
* @param {Boolean} isFirstTimeNewExpensifyUser
* @param {Boolean} openOnAdminRoom
* @returns {Object}
*/
const getInitialReportScreenParams = (reports, ignoreDefaultRooms, policies, openOnAdminRoom) => {
const last = ReportUtils.findLastAccessedReport(reports, ignoreDefaultRooms, policies, openOnAdminRoom);
const getInitialReportScreenParams = (reports, ignoreDefaultRooms, policies, isFirstTimeNewExpensifyUser, openOnAdminRoom) => {
const last = ReportUtils.findLastAccessedReport(reports, ignoreDefaultRooms, policies, isFirstTimeNewExpensifyUser, openOnAdminRoom);

// Fallback to empty if for some reason reportID cannot be derived - prevents the app from crashing
const reportID = lodashGet(last, 'reportID', '');
Expand All @@ -75,6 +79,7 @@ class MainDrawerNavigator extends Component {
props.reports,
!Permissions.canUseDefaultRooms(props.betas),
props.policies,
props.isFirstTimeNewExpensifyUser,
lodashGet(props, 'route.params.openOnAdminRoom', false),
);

Expand All @@ -88,6 +93,7 @@ class MainDrawerNavigator extends Component {
nextProps.reports,
!Permissions.canUseDefaultRooms(nextProps.betas),
nextProps.policies,
nextProps.isFirstTimeNewExpensifyUser,
lodashGet(nextProps, 'route.params.openOnAdminRoom', false),
);
if (this.initialParams.reportID === initialNextParams.reportID) {
Expand Down Expand Up @@ -156,4 +162,7 @@ export default withOnyx({
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
isFirstTimeNewExpensifyUser: {
key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER,
},
})(MainDrawerNavigator);
37 changes: 25 additions & 12 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,40 @@ function hasExpensifyGuidesEmails(emails) {
return _.some(emails, email => Str.extractEmailDomain(email) === CONST.EMAIL.GUIDES_DOMAIN);
}

/**
* Only returns true if this is our main 1:1 DM report with Concierge
*
* @param {Object} report
* @returns {Boolean}
*/
function isConciergeChatReport(report) {
return lodashGet(report, 'participants', []).length === 1
&& report.participants[0] === CONST.EMAIL.CONCIERGE;
}

/**
* @param {Record<String, {lastReadTime, reportID}>|Array<{lastReadTime, reportID}>} reports
* @param {Boolean} [ignoreDefaultRooms]
* @param {Object} policies
* @param {Boolean} isFirstTimeNewExpensifyUser
* @param {Boolean} openOnAdminRoom
* @returns {Object}
*/
function findLastAccessedReport(reports, ignoreDefaultRooms, policies, openOnAdminRoom = false) {
function findLastAccessedReport(reports, ignoreDefaultRooms, policies, isFirstTimeNewExpensifyUser, openOnAdminRoom = false) {
// If it's the user's first time using New Expensify, then they could either have:
// - just a Concierge report, if so we'll return that
// - their Concierge report, and a separate report that must have deeplinked them to the app before they created their account.
// If it's the latter, we'll use the deeplinked report over the Concierge report,
// since the Concierge report would be incorrectly selected over the deep-linked report in the logic below.
let sortedReports = sortReportsByLastRead(reports);

if (isFirstTimeNewExpensifyUser) {
if (sortedReports.length === 1) {
return sortedReports[0];
}
return _.find(sortedReports, report => !isConciergeChatReport(report));
}

if (ignoreDefaultRooms) {
// 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.
Expand Down Expand Up @@ -432,17 +456,6 @@ function getRoomWelcomeMessage(report, policiesMap) {
return welcomeMessage;
}

/**
* Only returns true if this is our main 1:1 DM report with Concierge
*
* @param {Object} report
* @returns {Boolean}
*/
function isConciergeChatReport(report) {
return lodashGet(report, 'participants', []).length === 1
&& report.participants[0] === CONST.EMAIL.CONCIERGE;
}

/**
* Returns true if Concierge is one of the chat participants (1:1 as well as group chats)
* @param {Object} report
Expand Down

0 comments on commit 57de036

Please sign in to comment.