diff --git a/src/components/parentPost/view/parentPostView.js b/src/components/parentPost/view/parentPostView.js index 1623fe57c..12d450a14 100644 --- a/src/components/parentPost/view/parentPostView.js +++ b/src/components/parentPost/view/parentPostView.js @@ -1,28 +1,34 @@ import React from 'react'; import { View, Text, TouchableOpacity } from 'react-native'; import { withNavigation } from 'react-navigation'; +import get from 'lodash/get'; import { default as ROUTES } from '../../../constants/routeNames'; + import styles from './parentPostStyles'; -const ParentPost = ({ post, navigation }) => ( - - (navigation && navigation.navigate - ? navigation.navigate({ - routeName: ROUTES.SCREENS.POST, - params: { - content: post, - }, - key: post.permlink, - }) - : null) +const ParentPost = (props) => { + const { navigation, post } = props; + + return ( + + (get(navigation, 'navigate') + ? navigation.navigate({ + routeName: ROUTES.SCREENS.POST, + params: { + content: post, + }, + key: post.permlink, + }) + : null) } - > - {post.title} - {post.summary} - - -); + > + {get(post, 'title')} + {get(post, 'summary')} + + + ); +}; export default withNavigation(ParentPost); diff --git a/src/components/postElements/body/view/postBodyView.js b/src/components/postElements/body/view/postBodyView.js index 01b6281d9..cff3956ea 100644 --- a/src/components/postElements/body/view/postBodyView.js +++ b/src/components/postElements/body/view/postBodyView.js @@ -7,7 +7,7 @@ import HTML from 'react-native-html-renderer'; import { getParentsTagsRecursively } from 'react-native-html-renderer/src/HTMLUtils'; // Utils -import { validateUsername } from '../../../../utils/user'; +import { validateUsername } from '../../../../utils/user'; // Styles import styles from './postBodyStyles'; @@ -94,14 +94,16 @@ class PostBody extends PureComponent { _handleOnPostPress = (permlink, author) => { const { navigation } = this.props; - navigation.navigate({ - routeName: ROUTES.SCREENS.POST, - params: { - author, - permlink, - }, - key: permlink, - }); + if (permlink) { + navigation.navigate({ + routeName: ROUTES.SCREENS.POST, + params: { + author, + permlink, + }, + key: permlink, + }); + } }; _handleOnUserPress = (username) => { diff --git a/src/screens/bookmarks/container/bookmarksContainer.js b/src/screens/bookmarks/container/bookmarksContainer.js index 239ae3531..692dd5832 100644 --- a/src/screens/bookmarks/container/bookmarksContainer.js +++ b/src/screens/bookmarks/container/bookmarksContainer.js @@ -117,13 +117,15 @@ class DraftsContainer extends Component { _handleOnBookarkPress = (permlink, author) => { const { navigation } = this.props; - navigation.navigate({ - routeName: ROUTES.SCREENS.POST, - params: { - permlink, - author, - }, - }); + if (permlink && author) { + navigation.navigate({ + routeName: ROUTES.SCREENS.POST, + params: { + permlink, + author, + }, + }); + } }; _sortData = data => data.sort((a, b) => { diff --git a/src/screens/editor/container/editorContainer.js b/src/screens/editor/container/editorContainer.js index 3e91770ee..75fd2f474 100644 --- a/src/screens/editor/container/editorContainer.js +++ b/src/screens/editor/container/editorContainer.js @@ -359,7 +359,7 @@ class EditorContainer extends Component { navigation.navigate({ routeName: ROUTES.SCREENS.POST, params: { - author: currentAccount.name, + author: get(currentAccount, 'name'), permlink, isNewPost: true, }, diff --git a/src/screens/notification/container/notificationContainer.js b/src/screens/notification/container/notificationContainer.js index ca03a8a3d..026c43e46 100644 --- a/src/screens/notification/container/notificationContainer.js +++ b/src/screens/notification/container/notificationContainer.js @@ -1,5 +1,6 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; +import get from 'lodash/get'; // Actions and Services import { getActivities, markActivityAsRead } from '../../../providers/esteem/esteem'; @@ -61,6 +62,9 @@ class NotificationContainer extends Component { _navigateToNotificationRoute = (data) => { const { navigation, username, dispatch } = this.props; + const type = get(data, 'type'); + const permlink = get(data, 'permlink'); + const author = get(data, 'author'); let routeName; let params; let key; @@ -68,30 +72,32 @@ class NotificationContainer extends Component { dispatch(updateUnreadActivityCount(result.unread)); }); - if (data.permlink) { + if (permlink) { routeName = ROUTES.SCREENS.POST; - key = data.permlink; + key = permlink; params = { - author: data.author, - permlink: data.permlink, - isHasParentPost: data.parent_author && data.parent_permlink, + author, + permlink, + isHasParentPost: get(data, 'parent_permlink'), }; - } else if (data.type === 'follow') { + } else if (type === 'follow') { routeName = ROUTES.SCREENS.PROFILE; - key = data.follower; + key = get(data, 'follower'); params = { - username: data.follower, + username: get(data, 'follower'), }; - } else if (data.type === 'transfer') { + } else if (type === 'transfer') { routeName = ROUTES.TABBAR.PROFILE; params = { activePage: 2 }; } - navigation.navigate({ - routeName, - params, - key, - }); + if (routeName) { + navigation.navigate({ + routeName, + params, + key, + }); + } }; _readAllNotification = () => { diff --git a/src/screens/root/container/rootContainer.js b/src/screens/root/container/rootContainer.js index 2a516e54e..a2d4b8c41 100644 --- a/src/screens/root/container/rootContainer.js +++ b/src/screens/root/container/rootContainer.js @@ -5,6 +5,7 @@ import { import { connect } from 'react-redux'; import Push from 'appcenter-push'; import { injectIntl } from 'react-intl'; +import get from 'lodash/get'; // Actions & Services import { openPinCodeModal } from '../../../redux/actions/applicationActions'; @@ -72,13 +73,15 @@ const RootContainer = () => (WrappedComponent) => { const routeParams = url.indexOf('/') > -1 ? url.split('/') : [url]; [, permlink] = routeParams; - author = routeParams[0].indexOf('@') > -1 ? routeParams[0].replace('@', '') : routeParams[0]; + author = routeParams && routeParams.length > 0 + && routeParams[0].indexOf('@') > -1 + ? routeParams[0].replace('@', '') : routeParams[0]; } if (author && permlink) { await getPost(author, permlink, currentAccountUsername) .then((result) => { - if (result && result.title) { + if (get(result, 'title')) { content = result; } else { this._handleAlert( @@ -111,10 +114,10 @@ const RootContainer = () => (WrappedComponent) => { } routeName = ROUTES.SCREENS.PROFILE; - params = { username: profile.name, reputation: profile.reputation }; + params = { username: get(profile, 'name'), reputation: get(profile, 'reputation') }; } - if (profile || content) { + if (routeName && (profile || content)) { this.navigationTimeout = setTimeout(() => { clearTimeout(this.navigationTimeout); navigation.navigate({ @@ -168,18 +171,27 @@ const RootContainer = () => (WrappedComponent) => { Push.setListener({ onPushNotificationReceived(pushNotification) { - const push = pushNotification.customProperties; + const push = get(pushNotification, 'customProperties'); + const permlink1 = get(push, 'permlink1'); + const permlink2 = get(push, 'permlink2'); + const permlink3 = get(push, 'permlink3'); + const parentPermlink1 = get(push, 'parent_permlink1'); + const parentPermlink2 = get(push, 'parent_permlink2'); + const parentPermlink3 = get(push, 'parent_permlink3'); + + if (parentPermlink1 || permlink1) { + const fullParentPermlink = `${parentPermlink1}${parentPermlink2}${parentPermlink3}`; + const fullPermlink = `${permlink1}${permlink2}${permlink3}`; - if (push.parent_permlink1 || push.permlink1) { params = { - author: push.parent_permlink1 ? push.parent_author : push.target, - permlink: push.parent_permlink1 - ? `${push.parent_permlink1}${push.parent_permlink2}${push.parent_permlink3}` - : `${push.permlink1}${push.permlink2}${push.permlink3}`, + author: parentPermlink1 ? get(push, 'parent_author') : get(push, 'target'), + permlink: parentPermlink1 + ? fullParentPermlink + : fullPermlink, }; - key = push.parent_permlink1 - ? `${push.parent_permlink1}${push.parent_permlink2}${push.parent_permlink3}` - : `${push.permlink1}${push.permlink2}${push.permlink3}`; + key = parentPermlink1 + ? fullParentPermlink + : fullPermlink; routeName = ROUTES.SCREENS.POST; } else { params = { @@ -189,7 +201,8 @@ const RootContainer = () => (WrappedComponent) => { routeName = ROUTES.SCREENS.PROFILE; } - setTimeout(() => { + this.pushNavigationTimeout = setTimeout(() => { + clearTimeout(this.pushNavigationTimeout); navigation.navigate({ routeName, params, key }); }, 4000); },