diff --git a/app/mattermost.js b/app/mattermost.js index 086c41a70..d7331ee6e 100644 --- a/app/mattermost.js +++ b/app/mattermost.js @@ -165,6 +165,7 @@ export default class Mattermost { popInitialNotification: true, requestPermissions: true }); + this.isConfigured = true; }; handleAppStateChange = async (appState) => { @@ -424,7 +425,6 @@ export default class Mattermost { } else if (isNotActive) { // for IOS replying from push notification starts the app in the background this.shouldRelaunchonActive = true; - this.configurePushNotifications(); this.startFakeApp(); } else { this.launchApp(); @@ -433,6 +433,7 @@ export default class Mattermost { }; onRegisterDevice = (data) => { + this.isConfigured = true; const {dispatch, getState} = this.store; let prefix; if (Platform.OS === 'ios') { @@ -445,7 +446,6 @@ export default class Mattermost { } setDeviceToken(`${prefix}:${data.token}`)(dispatch, getState); - this.isConfigured = true; }; onPushNotification = (deviceNotification) => { diff --git a/app/push_notifications/push_notifications.android.js b/app/push_notifications/push_notifications.android.js index a71192138..459431c5e 100644 --- a/app/push_notifications/push_notifications.android.js +++ b/app/push_notifications/push_notifications.android.js @@ -11,6 +11,11 @@ class PushNotification { this.onNotification = null; this.onReply = null; this.deviceNotification = null; + this.deviceToken = null; + + NotificationsAndroid.setRegistrationTokenUpdateListener((deviceToken) => { + this.deviceToken = deviceToken; + }); NotificationsAndroid.setNotificationReceivedListener((notification) => { if (notification) { @@ -61,12 +66,9 @@ class PushNotification { this.onNotification = options.onNotification; this.onReply = options.onReply; - NotificationsAndroid.refreshToken(); - NotificationsAndroid.setRegistrationTokenUpdateListener((deviceToken) => { - if (this.onRegister) { - this.onRegister({token: deviceToken}); - } - }); + if (this.onRegister && this.deviceToken) { + this.onRegister({token: this.deviceToken}); + } if (options.popInitialNotification) { PendingNotifications.getInitialNotification().