diff --git a/src/libs/API.js b/src/libs/API.js index ba07e8c9398ee..f7ce7d5c3fb3f 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -48,13 +48,14 @@ function addAuthTokenToParameters(command, parameters) { const finalParameters = {...parameters}; if (isAuthTokenRequired(command) && !parameters.authToken) { - // If we end up here with no authToken it means we are trying to make - // an API request before we are signed in. In this case, we should just - // cancel this and all other requests and set isAuthenticating to false. + // If we end up here with no authToken it means we are trying to make an API request before we are signed in. + // In this case, we should cancel the current request by pausing the queue and clearing the remaining requests. if (!authToken) { - console.debug('A request was made without an authToken', {command, parameters}); - Network.unpauseRequestQueue(); redirectToSignIn(); + + console.debug('A request was made without an authToken', {command, parameters}); + Network.pauseRequestQueue(); + Network.clearRequestQueue(); return; } diff --git a/src/libs/Network.js b/src/libs/Network.js index 0f56958771de2..37f6a9e6f78be 100644 --- a/src/libs/Network.js +++ b/src/libs/Network.js @@ -54,6 +54,12 @@ function processNetworkRequestQueue() { ? enhanceParameters(queuedRequest.command, queuedRequest.data) : queuedRequest.data; + // Check to see if the queue has paused again. It's possible that a call to enhanceParameters() + // has paused the queue and if this is the case we must return. + if (isQueuePaused) { + return; + } + HttpUtils.xhr(queuedRequest.command, finalParameters, queuedRequest.type) .then(queuedRequest.resolve) .catch(queuedRequest.reject); @@ -114,9 +120,17 @@ function registerParameterEnhancer(callback) { enhanceParameters = callback; } +/** + * Clear the queue so all pending requests will be cancelled + */ +function clearRequestQueue() { + networkRequestQueue = []; +} + export { post, pauseRequestQueue, unpauseRequestQueue, registerParameterEnhancer, + clearRequestQueue, }; diff --git a/src/libs/NetworkConnection.js b/src/libs/NetworkConnection.js index a2c26fb772894..2b57342b6b5c9 100644 --- a/src/libs/NetworkConnection.js +++ b/src/libs/NetworkConnection.js @@ -97,9 +97,11 @@ function stopListeningForReconnect() { clearInterval(sleepTimer); if (unsubscribeFromNetInfo) { unsubscribeFromNetInfo(); + unsubscribeFromNetInfo = undefined; } if (isListeningToAppStateChanges) { AppState.removeEventListener('change', setAppState); + isListeningToAppStateChanges = false; } } diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 78d9bceff5867..d4db7092e432d 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -610,7 +610,7 @@ function handleReportChanged(report) { // A report can be missing a name if a comment is received via pusher event // and the report does not yet exist in Onyx (eg. a new DM created with the logged in person) - if (report.reportName === undefined) { + if (report.reportID && report.reportName === undefined) { fetchChatReportsByIDs([report.reportID]); } diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index ebe14e439e534..9887d717732fc 100644 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -46,6 +46,7 @@ class ReportActionsView extends React.Component { this.scrollToListBottom = this.scrollToListBottom.bind(this); this.recordMaxAction = this.recordMaxAction.bind(this); this.sortedReportActions = this.updateSortedReportActions(); + this.timers = []; this.state = { refetchNeeded: true, @@ -55,7 +56,7 @@ class ReportActionsView extends React.Component { componentDidMount() { this.visibilityChangeEvent = AppState.addEventListener('change', () => { if (this.props.isActiveReport && Visibility.isVisible()) { - setTimeout(this.recordMaxAction, 3000); + this.timers.push(setTimeout(this.recordMaxAction, 3000)); } }); if (this.props.isActiveReport) { @@ -86,7 +87,7 @@ class ReportActionsView extends React.Component { // When the number of actions change, wait three seconds, then record the max action // This will make the unread indicator go away if you receive comments in the same chat you're looking at if (this.props.isActiveReport && Visibility.isVisible()) { - setTimeout(this.recordMaxAction, 3000); + this.timers.push(setTimeout(this.recordMaxAction, 3000)); } return; @@ -109,9 +110,12 @@ class ReportActionsView extends React.Component { if (this.keyboardEvent) { this.keyboardEvent.remove(); } + if (this.visibilityChangeEvent) { this.visibilityChangeEvent.remove(); } + + _.each(this.timers, timer => clearTimeout(timer)); } /**