From 98287110ffac8577b9cb5bb331e61868beb9c669 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Tue, 12 Feb 2019 19:07:01 +0300 Subject: [PATCH 1/2] fix for #466 --- src/screens/root/container/rootContainer.js | 35 +++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/screens/root/container/rootContainer.js b/src/screens/root/container/rootContainer.js index ae6dff4ea..cf2fd13f7 100644 --- a/src/screens/root/container/rootContainer.js +++ b/src/screens/root/container/rootContainer.js @@ -164,16 +164,39 @@ const RootContainer = () => (WrappedComponent) => { Push.setListener({ onPushNotificationReceived(pushNotification) { - if (AppState.currentState === 'background') { - if (pushNotification.customProperties.routeName) { + const extra = JSON.parse(pushNotification.customProperties.extra); + if (extra.parent_permlink) { + setTimeout(() => { navigation.navigate({ - routeName: pushNotification.customProperties.routeName, + routeName: ROUTES.SCREENS.POST, + params: { + author: extra.parent_author, + permlink: extra.parent_permlink, + }, + key: extra.parent_permlink, }); - } else { + }, 4000); + } else if (extra.permlink) { + setTimeout(() => { navigation.navigate({ - routeName: ROUTES.TABBAR.NOTIFICATION, + routeName: ROUTES.SCREENS.POST, + params: { + author: pushNotification.customProperties.target, + permlink: extra.permlink, + }, + key: extra.permlink, }); - } + }, 4000); + } else { + setTimeout(() => { + navigation.navigate({ + routeName: ROUTES.SCREENS.PROFILE, + params: { + username: pushNotification.customProperties.source, + }, + key: pushNotification.customProperties.source, + }); + }, 4000); } }, }); From 15cc7f3581b37facfbcf5507c17ec81c43c53cec Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Wed, 13 Feb 2019 11:19:34 +0300 Subject: [PATCH 2/2] Refactored #466 --- src/screens/root/container/rootContainer.js | 54 +++++++++------------ 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/screens/root/container/rootContainer.js b/src/screens/root/container/rootContainer.js index cf2fd13f7..89581c8af 100644 --- a/src/screens/root/container/rootContainer.js +++ b/src/screens/root/container/rootContainer.js @@ -161,43 +161,35 @@ const RootContainer = () => (WrappedComponent) => { _createPushListener = () => { const { navigation } = this.props; + let params = null; + let key = null; + let routeName = null; Push.setListener({ onPushNotificationReceived(pushNotification) { const extra = JSON.parse(pushNotification.customProperties.extra); - if (extra.parent_permlink) { - setTimeout(() => { - navigation.navigate({ - routeName: ROUTES.SCREENS.POST, - params: { - author: extra.parent_author, - permlink: extra.parent_permlink, - }, - key: extra.parent_permlink, - }); - }, 4000); - } else if (extra.permlink) { - setTimeout(() => { - navigation.navigate({ - routeName: ROUTES.SCREENS.POST, - params: { - author: pushNotification.customProperties.target, - permlink: extra.permlink, - }, - key: extra.permlink, - }); - }, 4000); + + if (extra.parent_permlink || extra.permlink) { + params = { + author: + extra.parent_permlink + ? extra.parent_author + : pushNotification.customProperties.target, + permlink: extra.parent_permlink ? extra.parent_permlink : extra.permlink, + }; + key = extra.parent_permlink ? extra.parent_permlink : extra.permlink; + routeName = ROUTES.SCREENS.POST; } else { - setTimeout(() => { - navigation.navigate({ - routeName: ROUTES.SCREENS.PROFILE, - params: { - username: pushNotification.customProperties.source, - }, - key: pushNotification.customProperties.source, - }); - }, 4000); + params = { + username: pushNotification.customProperties.source, + }; + key = pushNotification.customProperties.source; + routeName = ROUTES.SCREENS.PROFILE; } + + setTimeout(() => { + navigation.navigate({ routeName, params, key }); + }, 4000); }, }); };