diff --git a/src/libs/Notification/PushNotification/index.js b/src/libs/Notification/PushNotification/index.js index c4100583442d..88136ff5dc72 100644 --- a/src/libs/Notification/PushNotification/index.js +++ b/src/libs/Notification/PushNotification/index.js @@ -2,6 +2,7 @@ import NotificationType from './NotificationType'; // Push notifications are only supported on mobile, so we'll just noop here export default { + init: () => {}, register: () => {}, deregister: () => {}, onReceived: () => {}, diff --git a/src/libs/Notification/PushNotification/index.native.js b/src/libs/Notification/PushNotification/index.native.js index 4dc3ad1c3a8e..b6787858191d 100644 --- a/src/libs/Notification/PushNotification/index.native.js +++ b/src/libs/Notification/PushNotification/index.native.js @@ -4,8 +4,6 @@ import {UrbanAirship, EventType, iOS} from 'urbanairship-react-native'; import lodashGet from 'lodash/get'; import Log from '../../Log'; import NotificationType from './NotificationType'; -import PushNotification from '.'; -import * as Report from '../../actions/Report'; const notificationEventActionMap = {}; @@ -109,12 +107,6 @@ function register(accountID) { // Regardless of the user's opt-in status, we still want to receive silent push notifications. Log.info(`[PUSH_NOTIFICATIONS] Subscribing to notifications for account ID ${accountID}`); UrbanAirship.setNamedUser(accountID.toString()); - - // When the user logged out and then logged in with a different account - // while the app is still in background, we must resubscribe to the report - // push notification in order to render the report click behaviour correctly - PushNotification.init(); - Report.subscribeToReportCommentPushNotifications(); } /** diff --git a/src/libs/actions/Session/index.js b/src/libs/actions/Session/index.js index bcf3f0919de2..0ca656a95d42 100644 --- a/src/libs/actions/Session/index.js +++ b/src/libs/actions/Session/index.js @@ -15,6 +15,7 @@ import * as Authentication from '../../Authentication'; import * as Welcome from '../Welcome'; import * as API from '../../API'; import * as NetworkStore from '../../Network/NetworkStore'; +import * as Report from '../Report'; import DateUtils from '../../DateUtils'; let credentials = {}; @@ -40,6 +41,10 @@ Onyx.connect({ if (accountID) { PushNotification.register(accountID); + + // Prevent issue where report linking fails after users switch accounts without closing the app + PushNotification.init(); + Report.subscribeToReportCommentPushNotifications(); } else { PushNotification.deregister(); PushNotification.clearNotifications();