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
25 changes: 20 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 fetching a single chat that is inacessible.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* when fetching a single chat that is inacessible.
* 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 && chatList.length === 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. not sure checking the chatList is necessary on second thought
  2. we should be checking shouldRedirectIfInacessible when we throw this error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. If we're controlling the redirect via the shouldRedirectIfInacessible param, checking the chatList is a weird restriction.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (jsonCode === 404 && chatList.length === 1) {
if (jsonCode === 404 && shouldRedirectIfInacessible) {

throw new Error('inacessible');
Copy link
Contributor

@marcaaron marcaaron Jul 14, 2021

Choose a reason for hiding this comment

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

Can we perhaps create a constant for this and maybe give it a slightly more descriptive error something like this?

const CONST = {
    ...,
    ERROR: {
        INACCESSIBLE_REPORT: 'Report not found',
    },
};

Copy link
Contributor

Choose a reason for hiding this comment

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

Then we can use CONST.ERROR.INACCESSIBLE_REPORT in these two locations.

}

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,14 @@ function fetchChatReportsByIDs(chatList) {
PersonalDetails.getFromReportParticipants(Object.values(simplifiedReports));

return _.map(fetchedReports, report => report.reportID);
})
.catch((err) => {
if (err.message === 'inacessible' && shouldRedirectIfInacessible) {
Log.info('[Report] Report data is inacessible.', true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's maybe get rid of this log since it will actually print to the server and we don't need it to do that in this case.

Growl.error(translateLocal('notFound.chatYouLookingForCannotBeFound'));
// eslint-disable-next-line no-use-before-define
navigateToConciergeChat();
}
});
}

Expand Down
4 changes: 4 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,9 @@ class ReportActionsView extends React.Component {

componentDidMount() {
AppState.addEventListener('change', this.onVisibilityChange);
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