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 a growl and redirect when navigating to a chat we can't access #4018

Merged
merged 12 commits into from
Jul 19, 2021
3 changes: 3 additions & 0 deletions src/CONST.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 19 additions & 5 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,19 +298,26 @@ function fetchIOUReportID(debtorEmail) {
}

/**
* Fetches chat reports when provided a list of
* chat report IDs
*
* Fetches chat reports when provided a list of chat report IDs.
* If the shouldRedirectIfInacessible flag is set, we redirect to the Concierge chat
* when we find an inaccessible chat
* @param {Array} chatList
* @param {Boolean} shouldRedirectIfInacessible
* @returns {Promise<Number[]>} only used internally when fetchAllReports() is called
*/
function fetchChatReportsByIDs(chatList) {
function fetchChatReportsByIDs(chatList, shouldRedirectIfInacessible = false) {
let fetchedReports;
const simplifiedReports = {};
return API.GetReportSummaryList({reportIDList: chatList.join(',')})
.then(({reportSummaryList}) => {
.then(({reportSummaryList, jsonCode}) => {
Log.info('[Report] successfully fetched report data', true);
fetchedReports = reportSummaryList;

// If we receive a 404 response while fetching a single report, treat that report as inacessible.
if (jsonCode === 404 && shouldRedirectIfInacessible) {
throw new Error(CONST.REPORT.ERROR.INACCESSIBLE_REPORT);
}

return Promise.all(_.map(fetchedReports, (chatReport) => {
// If there aren't any IOU actions, we don't need to fetch any additional data
if (!chatReport.hasIOUAction) {
Expand Down Expand Up @@ -368,6 +375,13 @@ function fetchChatReportsByIDs(chatList) {
PersonalDetails.getFromReportParticipants(Object.values(simplifiedReports));

return _.map(fetchedReports, report => report.reportID);
})
.catch((err) => {
if (err.message === CONST.REPORT.ERROR.INACCESSIBLE_REPORT) {
Growl.error(translateLocal('notFound.chatYouLookingForCannotBeFound'));
// eslint-disable-next-line no-use-before-define
navigateToConciergeChat();
}
});
}

Expand Down
7 changes: 7 additions & 0 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {withOnyx} from 'react-native-onyx';
import Text from '../../../components/Text';
import {
fetchActions,
fetchChatReportsByIDs,
updateLastReadActionID,
setNewMarkerPosition,
subscribeToReportTypingEvents,
Expand Down Expand Up @@ -107,6 +108,12 @@ class ReportActionsView extends React.Component {

componentDidMount() {
AppState.addEventListener('change', this.onVisibilityChange);

// If the reportID is not found then we have either not loaded this chat or the user is unable to access it.
// We will attempt to fetch it and redirect if still not accessible.
if (!this.props.report.reportID) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like there's a special significance to this not existing. Can we add a comment above to maybe explain why this does not exist and why it's being called with this parameter? Maybe something like

If the reportID is not found then we have either not loaded this chat or the user is unable to access it. We will attempt to fetch it and redirect if still not accessible.

fetchChatReportsByIDs([this.props.reportID], true);
}
subscribeToReportTypingEvents(this.props.reportID);
this.keyboardEvent = Keyboard.addListener('keyboardDidShow', () => {
if (ReportActionComposeFocusManager.isFocused()) {
Expand Down