From 778bb69e0c11c2faf86f8087e9d4f862e2f97d8c Mon Sep 17 00:00:00 2001 From: Maximilian Stoiber Date: Tue, 12 Jun 2018 10:28:59 +0200 Subject: [PATCH 1/2] Fix viewing new profiles on mobile Viewing a profile that didn't have any data loaded for it yet broke without these security changes. --- mobile/views/Channel/index.js | 4 +++- mobile/views/Community/index.js | 4 +++- .../components/DirectMessageThread.js | 4 +++- mobile/views/TabBar/BaseStack.js | 9 +++++---- mobile/views/Thread/index.js | 4 +++- mobile/views/User/profile.js | 5 ++++- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/mobile/views/Channel/index.js b/mobile/views/Channel/index.js index bb05f46760..17b7a23403 100644 --- a/mobile/views/Channel/index.js +++ b/mobile/views/Channel/index.js @@ -1,6 +1,7 @@ // @flow import React, { Component } from 'react'; import compose from 'recompose/compose'; +import idx from 'idx'; import { getChannelById, type GetChannelType, @@ -57,7 +58,8 @@ class Channel extends Component { } else { title = 'Loading channel...'; } - if (navigation.state.params.title === title) return; + const oldTitle = idx(navigation, _ => _.state.params.title); + if (oldTitle && oldTitle === title) return; navigation.setParams({ title }); }; diff --git a/mobile/views/Community/index.js b/mobile/views/Community/index.js index 3f54db93e7..7b39e28cf2 100644 --- a/mobile/views/Community/index.js +++ b/mobile/views/Community/index.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import compose from 'recompose/compose'; import { withNavigation } from 'react-navigation'; +import idx from 'idx'; import { getCommunityById, type GetCommunityType, @@ -78,7 +79,8 @@ class Community extends Component { } else { title = 'Loading community...'; } - if (navigation.state.params.title === title) return; + const oldTitle = idx(navigation, _ => _.state.params.title); + if (oldTitle && oldTitle === title) return; navigation.setParams({ title }); }; diff --git a/mobile/views/DirectMessageThread/components/DirectMessageThread.js b/mobile/views/DirectMessageThread/components/DirectMessageThread.js index 45ead568ed..9ac1a94ca9 100644 --- a/mobile/views/DirectMessageThread/components/DirectMessageThread.js +++ b/mobile/views/DirectMessageThread/components/DirectMessageThread.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import { View } from 'react-native'; import compose from 'recompose/compose'; +import idx from 'idx'; import Text from '../../../components/Text'; import ChatInput from '../../../components/ChatInput'; import Messages from '../../../components/Messages'; @@ -52,7 +53,8 @@ class DirectMessageThread extends Component { let title = directMessageThread ? sentencify(directMessageThread.participants.map(({ name }) => name)) : 'Loading thread...'; - if (navigation.state.params.title === title) return; + const oldTitle = idx(navigation, _ => _.state.params.title); + if (oldTitle && oldTitle === title) return; navigation.setParams({ title }); }; diff --git a/mobile/views/TabBar/BaseStack.js b/mobile/views/TabBar/BaseStack.js index 09d44d63b6..a23b2ca7c0 100644 --- a/mobile/views/TabBar/BaseStack.js +++ b/mobile/views/TabBar/BaseStack.js @@ -1,6 +1,7 @@ // @flow // The basic view stack that's used on all of our screens // Any view that's added here can be visited from any of our tabs +import idx from 'idx'; import Thread from '../Thread'; import Community from '../Community'; import Channel from '../Channel'; @@ -12,26 +13,26 @@ const BaseStack = { Thread: { screen: withMappedNavigationProps(Thread), navigationOptions: ({ navigation }: NavigationScreenConfigProps) => ({ - headerTitle: navigation.state.params.title || null, + headerTitle: idx(navigation, _ => _.state.params.title) || null, tabBarVisible: false, }), }, Community: { screen: withMappedNavigationProps(Community), navigationOptions: ({ navigation }: NavigationScreenConfigProps) => ({ - headerTitle: navigation.state.params.title || null, + headerTitle: idx(navigation, _ => _.state.params.title) || null, }), }, Channel: { screen: withMappedNavigationProps(Channel), navigationOptions: ({ navigation }: NavigationScreenConfigProps) => ({ - headerTitle: navigation.state.params.title || null, + headerTitle: idx(navigation, _ => _.state.params.title) || null, }), }, User: { screen: withMappedNavigationProps(User), navigationOptions: ({ navigation }: NavigationScreenConfigProps) => ({ - headerTitle: navigation.state.params.title || null, + headerTitle: idx(navigation, _ => _.state.params.title) || null, }), }, }; diff --git a/mobile/views/Thread/index.js b/mobile/views/Thread/index.js index 69b67decc7..020f6f8eb3 100644 --- a/mobile/views/Thread/index.js +++ b/mobile/views/Thread/index.js @@ -3,6 +3,7 @@ import React, { Component } from 'react'; import { ScrollView } from 'react-native'; import compose from 'recompose/compose'; import { connect } from 'react-redux'; +import idx from 'idx'; import { getThreadById } from '../../../shared/graphql/queries/thread/getThread'; import ViewNetworkHandler from '../../components/ViewNetworkHandler'; import withSafeView from '../../components/SafeAreaView'; @@ -59,7 +60,8 @@ class Thread extends Component { } else { title = 'Loading thread...'; } - if (navigation.state.params.title === title) return; + const oldTitle = idx(navigation, _ => _.state.params.title); + if (oldTitle && oldTitle === title) return; navigation.setParams({ title }); }; diff --git a/mobile/views/User/profile.js b/mobile/views/User/profile.js index 16cf372a5d..d3389c7301 100644 --- a/mobile/views/User/profile.js +++ b/mobile/views/User/profile.js @@ -1,6 +1,7 @@ // @flow import React, { Component } from 'react'; import compose from 'recompose/compose'; +import idx from 'idx'; import getUserThreadConnection from '../../../shared/graphql/queries/user/getUserThreadConnection'; import ThreadFeed from '../../components/ThreadFeed'; import type { GetUserType } from '../../../shared/graphql/queries/user/getUser'; @@ -50,7 +51,9 @@ class User extends Component { } else { title = 'Loading user...'; } - if (navigation.state.params.title === title) return; + + const oldTitle = idx(navigation, _ => _.state.params.title); + if (oldTitle && oldTitle === title) return; navigation.setParams({ title }); }; From d6f82043194740d7643785366ddffb78e0d45031 Mon Sep 17 00:00:00 2001 From: Maximilian Stoiber Date: Tue, 12 Jun 2018 10:43:37 +0200 Subject: [PATCH 2/2] Use built-in react-navigation getParam method --- mobile/views/Channel/index.js | 3 +-- mobile/views/Community/index.js | 3 +-- .../components/DirectMessageThread.js | 3 +-- mobile/views/DirectMessageThread/index.js | 3 +-- mobile/views/TabBar/BaseStack.js | 9 ++++----- mobile/views/TabBar/DirectMessageStack.js | 5 ++--- mobile/views/Thread/index.js | 3 +-- mobile/views/User/profile.js | 3 +-- 8 files changed, 12 insertions(+), 20 deletions(-) diff --git a/mobile/views/Channel/index.js b/mobile/views/Channel/index.js index 17b7a23403..b8634a7280 100644 --- a/mobile/views/Channel/index.js +++ b/mobile/views/Channel/index.js @@ -1,7 +1,6 @@ // @flow import React, { Component } from 'react'; import compose from 'recompose/compose'; -import idx from 'idx'; import { getChannelById, type GetChannelType, @@ -58,7 +57,7 @@ class Channel extends Component { } else { title = 'Loading channel...'; } - const oldTitle = idx(navigation, _ => _.state.params.title); + const oldTitle = navigation.getParam('title', null); if (oldTitle && oldTitle === title) return; navigation.setParams({ title }); }; diff --git a/mobile/views/Community/index.js b/mobile/views/Community/index.js index 7b39e28cf2..2a989e13d5 100644 --- a/mobile/views/Community/index.js +++ b/mobile/views/Community/index.js @@ -2,7 +2,6 @@ import React, { Component } from 'react'; import compose from 'recompose/compose'; import { withNavigation } from 'react-navigation'; -import idx from 'idx'; import { getCommunityById, type GetCommunityType, @@ -79,7 +78,7 @@ class Community extends Component { } else { title = 'Loading community...'; } - const oldTitle = idx(navigation, _ => _.state.params.title); + const oldTitle = navigation.getParam('title', null); if (oldTitle && oldTitle === title) return; navigation.setParams({ title }); }; diff --git a/mobile/views/DirectMessageThread/components/DirectMessageThread.js b/mobile/views/DirectMessageThread/components/DirectMessageThread.js index 9ac1a94ca9..08ab8e24e7 100644 --- a/mobile/views/DirectMessageThread/components/DirectMessageThread.js +++ b/mobile/views/DirectMessageThread/components/DirectMessageThread.js @@ -2,7 +2,6 @@ import React, { Component } from 'react'; import { View } from 'react-native'; import compose from 'recompose/compose'; -import idx from 'idx'; import Text from '../../../components/Text'; import ChatInput from '../../../components/ChatInput'; import Messages from '../../../components/Messages'; @@ -53,7 +52,7 @@ class DirectMessageThread extends Component { let title = directMessageThread ? sentencify(directMessageThread.participants.map(({ name }) => name)) : 'Loading thread...'; - const oldTitle = idx(navigation, _ => _.state.params.title); + const oldTitle = navigation.getParam('title', null); if (oldTitle && oldTitle === title) return; navigation.setParams({ title }); }; diff --git a/mobile/views/DirectMessageThread/index.js b/mobile/views/DirectMessageThread/index.js index 9668259d4d..ebae979dcf 100644 --- a/mobile/views/DirectMessageThread/index.js +++ b/mobile/views/DirectMessageThread/index.js @@ -1,7 +1,6 @@ // @flow import React from 'react'; import compose from 'recompose/compose'; -import idx from 'idx'; import Text from '../../components/Text'; import { withCurrentUser } from '../../components/WithCurrentUser'; import DirectMessageThread from './components/DirectMessageThread'; @@ -17,8 +16,8 @@ type Props = { class DirectMessageThreadView extends React.Component { render() { - const id = idx(this.props, props => props.navigation.state.params.id); const { currentUser, navigation } = this.props; + const id = navigation.getParam('id', null); if (!id) return Non-existant DM thread; if (!currentUser) return null; diff --git a/mobile/views/TabBar/BaseStack.js b/mobile/views/TabBar/BaseStack.js index a23b2ca7c0..371196ef14 100644 --- a/mobile/views/TabBar/BaseStack.js +++ b/mobile/views/TabBar/BaseStack.js @@ -1,7 +1,6 @@ // @flow // The basic view stack that's used on all of our screens // Any view that's added here can be visited from any of our tabs -import idx from 'idx'; import Thread from '../Thread'; import Community from '../Community'; import Channel from '../Channel'; @@ -13,26 +12,26 @@ const BaseStack = { Thread: { screen: withMappedNavigationProps(Thread), navigationOptions: ({ navigation }: NavigationScreenConfigProps) => ({ - headerTitle: idx(navigation, _ => _.state.params.title) || null, + headerTitle: navigation.getParam('title', null), tabBarVisible: false, }), }, Community: { screen: withMappedNavigationProps(Community), navigationOptions: ({ navigation }: NavigationScreenConfigProps) => ({ - headerTitle: idx(navigation, _ => _.state.params.title) || null, + headerTitle: navigation.getParam('title', null), }), }, Channel: { screen: withMappedNavigationProps(Channel), navigationOptions: ({ navigation }: NavigationScreenConfigProps) => ({ - headerTitle: idx(navigation, _ => _.state.params.title) || null, + headerTitle: navigation.getParam('title', null), }), }, User: { screen: withMappedNavigationProps(User), navigationOptions: ({ navigation }: NavigationScreenConfigProps) => ({ - headerTitle: idx(navigation, _ => _.state.params.title) || null, + headerTitle: navigation.getParam('title', null), }), }, }; diff --git a/mobile/views/TabBar/DirectMessageStack.js b/mobile/views/TabBar/DirectMessageStack.js index 75278ce3b3..db52e60f7e 100644 --- a/mobile/views/TabBar/DirectMessageStack.js +++ b/mobile/views/TabBar/DirectMessageStack.js @@ -1,6 +1,5 @@ // @flow import { createStackNavigator } from 'react-navigation'; -import idx from 'idx'; import BaseStack from './BaseStack'; import DirectMessages from '../DirectMessages'; import DirectMessageThread from '../DirectMessageThread'; @@ -10,13 +9,13 @@ const DMStack = createStackNavigator( DirectMessages: { screen: DirectMessages, navigationOptions: ({ navigation }) => ({ - headerTitle: idx(navigation, _ => _.state.params.title) || 'Messages', + headerTitle: navigation.getParam('title', 'Messages'), }), }, DirectMessageThread: { screen: DirectMessageThread, navigationOptions: ({ navigation }) => ({ - headerTitle: idx(navigation, _ => _.state.params.title) || '', + headerTitle: navigation.getParam('title', null), tabBarVisible: false, }), }, diff --git a/mobile/views/Thread/index.js b/mobile/views/Thread/index.js index 020f6f8eb3..0f7260d2f6 100644 --- a/mobile/views/Thread/index.js +++ b/mobile/views/Thread/index.js @@ -3,7 +3,6 @@ import React, { Component } from 'react'; import { ScrollView } from 'react-native'; import compose from 'recompose/compose'; import { connect } from 'react-redux'; -import idx from 'idx'; import { getThreadById } from '../../../shared/graphql/queries/thread/getThread'; import ViewNetworkHandler from '../../components/ViewNetworkHandler'; import withSafeView from '../../components/SafeAreaView'; @@ -60,7 +59,7 @@ class Thread extends Component { } else { title = 'Loading thread...'; } - const oldTitle = idx(navigation, _ => _.state.params.title); + const oldTitle = navigation.getParam('title', null); if (oldTitle && oldTitle === title) return; navigation.setParams({ title }); }; diff --git a/mobile/views/User/profile.js b/mobile/views/User/profile.js index d3389c7301..dc61e0a3d0 100644 --- a/mobile/views/User/profile.js +++ b/mobile/views/User/profile.js @@ -1,7 +1,6 @@ // @flow import React, { Component } from 'react'; import compose from 'recompose/compose'; -import idx from 'idx'; import getUserThreadConnection from '../../../shared/graphql/queries/user/getUserThreadConnection'; import ThreadFeed from '../../components/ThreadFeed'; import type { GetUserType } from '../../../shared/graphql/queries/user/getUser'; @@ -52,7 +51,7 @@ class User extends Component { title = 'Loading user...'; } - const oldTitle = idx(navigation, _ => _.state.params.title); + const oldTitle = navigation.getParam('title', null); if (oldTitle && oldTitle === title) return; navigation.setParams({ title }); };