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

Stop loading default chat room initally for those outside of beta #5338

Merged
merged 4 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 18 additions & 3 deletions src/libs/Navigation/AppNavigator/MainDrawerNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {withOnyx} from 'react-native-onyx';
import FullScreenLoadingIndicator from '../../../components/FullscreenLoadingIndicator';
import ONYXKEYS from '../../../ONYXKEYS';
import SCREENS from '../../../SCREENS';
import Permissions from '../../Permissions';

// Screens
import ReportScreen from '../../../pages/home/ReportScreen';
Expand All @@ -18,23 +19,34 @@ const propTypes = {
reports: PropTypes.objectOf(PropTypes.shape({
reportID: PropTypes.number,
})),

/** Beta features list */
betas: PropTypes.arrayOf(PropTypes.string),
};

const defaultProps = {
reports: {},
betas: [],
};


const getInitialReportScreenParams = (reports) => {
const last = findLastAccessedReport(reports);
/**
* Get the most recently accessed report for the user
*
* @param {Object} reports
* @param {Boolean} [ignoreDefaultRooms]
* @returns {Object}
*/
const getInitialReportScreenParams = (reports, ignoreDefaultRooms) => {
const last = findLastAccessedReport(reports, ignoreDefaultRooms);

// Fallback to empty if for some reason reportID cannot be derived - prevents the app from crashing
const reportID = lodashGet(last, 'reportID', '');
return {reportID: String(reportID)};
};

const MainDrawerNavigator = (props) => {
const initialParams = getInitialReportScreenParams(props.reports);
const initialParams = getInitialReportScreenParams(props.reports, !Permissions.canUseDefaultRooms(props.betas));

// Wait until reports are fetched and there is a reportID in initialParams
if (!initialParams.reportID) {
Expand Down Expand Up @@ -67,5 +79,8 @@ export default withOnyx({
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
},
betas: {
key: ONYXKEYS.BETAS,
},
})(MainDrawerNavigator);
export {getInitialReportScreenParams};
28 changes: 17 additions & 11 deletions src/libs/reportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,6 @@ function canDeleteReportAction(reportAction) {
&& reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT;
}


/**
* Given a collection of reports returns the most recently accessed one
*
* @param {Record<String, {lastVisitedTimestamp, reportID}>|Array<{lastVisitedTimestamp, reportID}>} reports
* @returns {Object}
*/
function findLastAccessedReport(reports) {
return _.last(sortReportsByLastVisited(reports));
}

/**
* Whether the provided report is a default room
* @param {Object} report
Expand All @@ -102,6 +91,23 @@ function isDefaultRoom(report) {
], lodashGet(report, ['chatType'], ''));
}

/**
* Given a collection of reports returns the most recently accessed one
*
* @param {Record<String, {lastVisitedTimestamp, reportID}>|Array<{lastVisitedTimestamp, reportID}>} reports
* @param {Boolean} [ignoreDefaultRooms]
* @returns {Object}
*/
function findLastAccessedReport(reports, ignoreDefaultRooms) {
let sortedReports = sortReportsByLastVisited(reports);

if (ignoreDefaultRooms) {
sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report));
}

return _.last(sortedReports);
}

/**
* Whether the provided report is an archived room
* @param {Object} report
Expand Down
13 changes: 13 additions & 0 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import {handleInaccessibleReport, updateCurrentlyViewedReportID, addAction} from '../../libs/actions/Report';
import ONYXKEYS from '../../ONYXKEYS';
import Permissions from '../../libs/Permissions';
import {isDefaultRoom} from '../../libs/reportUtils';

import ReportActionsView from './report/ReportActionsView';
import ReportActionCompose from './report/ReportActionCompose';
Expand Down Expand Up @@ -54,6 +56,9 @@ const propTypes = {

/** Array of report actions for this report */
reportActions: PropTypes.objectOf(PropTypes.shape(ReportActionPropTypes)),

/** Beta features list */
betas: PropTypes.arrayOf(PropTypes.string),
};

const defaultProps = {
Expand All @@ -67,6 +72,7 @@ const defaultProps = {
maxSequenceNumber: 0,
hasOutstandingIOU: false,
},
betas: [],
};

/**
Expand Down Expand Up @@ -153,6 +159,10 @@ class ReportScreen extends React.Component {
return null;
}

if (!Permissions.canUseDefaultRooms(this.props.betas) && isDefaultRoom(this.props.report)) {
return null;
}

const reportID = getReportID(this.props.route);
return (
<ScreenWrapper style={[styles.appContent, styles.flex1]}>
Expand Down Expand Up @@ -208,4 +218,7 @@ export default withOnyx({
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`,
},
betas: {
key: ONYXKEYS.BETAS,
},
})(ReportScreen);