2019-03-12 16:23:06 +00:00
|
|
|
import React from 'react';
|
2019-09-17 19:24:47 +00:00
|
|
|
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
|
|
|
|
import { createStackNavigator } from 'react-navigation-stack';
|
|
|
|
import { createDrawerNavigator } from 'react-navigation-drawer';
|
2019-03-12 16:23:06 +00:00
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
import { useScreens } from 'react-native-screens'; // eslint-disable-line import/no-unresolved
|
2019-01-29 19:52:56 +00:00
|
|
|
import { Linking } from 'react-native';
|
2019-06-10 16:23:19 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-09-01 19:42:50 +00:00
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
import { appInit } from './actions';
|
2018-07-10 13:40:32 +00:00
|
|
|
import { deepLinkingOpen } from './actions/deepLinking';
|
2019-02-07 16:04:41 +00:00
|
|
|
import Navigation from './lib/Navigation';
|
2019-03-12 16:23:06 +00:00
|
|
|
import Sidebar from './views/SidebarView';
|
2018-07-10 13:40:32 +00:00
|
|
|
import parseQuery from './lib/methods/helpers/parseQuery';
|
2019-06-10 16:23:19 +00:00
|
|
|
import { initializePushNotifications, onNotification } from './notifications/push';
|
2019-03-12 16:23:06 +00:00
|
|
|
import store from './lib/createStore';
|
2019-06-10 16:23:19 +00:00
|
|
|
import NotificationBadge from './notifications/inApp';
|
2019-07-18 17:44:02 +00:00
|
|
|
import { defaultHeader, onNavigationStateChange } from './utils/navigation';
|
2019-08-23 13:18:47 +00:00
|
|
|
import { loggerConfig, analytics } from './utils/log';
|
2019-07-23 14:02:57 +00:00
|
|
|
import Toast from './containers/Toast';
|
2019-08-23 13:18:47 +00:00
|
|
|
import RocketChat from './lib/rocketchat';
|
2017-08-21 00:11:46 +00:00
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
useScreens();
|
2018-11-14 21:42:03 +00:00
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
const parseDeepLinking = (url) => {
|
2018-07-10 13:40:32 +00:00
|
|
|
if (url) {
|
|
|
|
url = url.replace(/rocketchat:\/\/|https:\/\/go.rocket.chat\//, '');
|
|
|
|
const regex = /^(room|auth)\?/;
|
|
|
|
if (url.match(regex)) {
|
2019-03-18 18:52:38 +00:00
|
|
|
url = url.replace(regex, '').trim();
|
|
|
|
if (url) {
|
|
|
|
return parseQuery(url);
|
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-18 18:52:38 +00:00
|
|
|
return null;
|
2018-07-10 13:40:32 +00:00
|
|
|
};
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
// Outside
|
|
|
|
const OutsideStack = createStackNavigator({
|
|
|
|
OnboardingView: {
|
2019-07-17 13:37:20 +00:00
|
|
|
getScreen: () => require('./views/OnboardingView').default,
|
2019-03-12 16:23:06 +00:00
|
|
|
header: null
|
|
|
|
},
|
2019-07-17 13:37:20 +00:00
|
|
|
NewServerView: {
|
|
|
|
getScreen: () => require('./views/NewServerView').default
|
|
|
|
},
|
|
|
|
LoginSignupView: {
|
|
|
|
getScreen: () => require('./views/LoginSignupView').default
|
|
|
|
},
|
|
|
|
LoginView: {
|
|
|
|
getScreen: () => require('./views/LoginView').default
|
|
|
|
},
|
|
|
|
ForgotPasswordView: {
|
|
|
|
getScreen: () => require('./views/ForgotPasswordView').default
|
|
|
|
},
|
|
|
|
RegisterView: {
|
|
|
|
getScreen: () => require('./views/RegisterView').default
|
|
|
|
},
|
|
|
|
LegalView: {
|
|
|
|
getScreen: () => require('./views/LegalView').default
|
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
2019-08-09 17:28:46 +00:00
|
|
|
const AuthenticationWebViewStack = createStackNavigator({
|
|
|
|
AuthenticationWebView: {
|
|
|
|
getScreen: () => require('./views/AuthenticationWebView').default
|
2019-07-17 13:37:20 +00:00
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
|
|
|
const OutsideStackModal = createStackNavigator({
|
|
|
|
OutsideStack,
|
2019-08-09 17:28:46 +00:00
|
|
|
AuthenticationWebViewStack
|
2019-03-12 16:23:06 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: 'modal',
|
|
|
|
headerMode: 'none'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Inside
|
|
|
|
const ChatsStack = createStackNavigator({
|
2019-07-17 13:37:20 +00:00
|
|
|
RoomsListView: {
|
|
|
|
getScreen: () => require('./views/RoomsListView').default
|
|
|
|
},
|
|
|
|
RoomView: {
|
|
|
|
getScreen: () => require('./views/RoomView').default
|
|
|
|
},
|
|
|
|
RoomActionsView: {
|
|
|
|
getScreen: () => require('./views/RoomActionsView').default
|
|
|
|
},
|
|
|
|
RoomInfoView: {
|
|
|
|
getScreen: () => require('./views/RoomInfoView').default
|
|
|
|
},
|
|
|
|
RoomInfoEditView: {
|
|
|
|
getScreen: () => require('./views/RoomInfoEditView').default
|
|
|
|
},
|
|
|
|
RoomMembersView: {
|
|
|
|
getScreen: () => require('./views/RoomMembersView').default
|
|
|
|
},
|
|
|
|
SearchMessagesView: {
|
|
|
|
getScreen: () => require('./views/SearchMessagesView').default
|
|
|
|
},
|
|
|
|
SelectedUsersView: {
|
|
|
|
getScreen: () => require('./views/SelectedUsersView').default
|
|
|
|
},
|
|
|
|
ThreadMessagesView: {
|
|
|
|
getScreen: () => require('./views/ThreadMessagesView').default
|
|
|
|
},
|
|
|
|
MessagesView: {
|
|
|
|
getScreen: () => require('./views/MessagesView').default
|
|
|
|
},
|
|
|
|
AutoTranslateView: {
|
|
|
|
getScreen: () => require('./views/AutoTranslateView').default
|
|
|
|
},
|
|
|
|
ReadReceiptsView: {
|
|
|
|
getScreen: () => require('./views/ReadReceiptView').default
|
|
|
|
},
|
|
|
|
DirectoryView: {
|
|
|
|
getScreen: () => require('./views/DirectoryView').default
|
2019-08-23 16:24:15 +00:00
|
|
|
},
|
2019-08-27 12:25:38 +00:00
|
|
|
TableView: {
|
|
|
|
getScreen: () => require('./views/TableView').default
|
|
|
|
},
|
2019-08-23 16:24:15 +00:00
|
|
|
NotificationPrefView: {
|
|
|
|
getScreen: () => require('./views/NotificationPreferencesView').default
|
2019-07-17 13:37:20 +00:00
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
2019-04-18 13:43:44 +00:00
|
|
|
ChatsStack.navigationOptions = ({ navigation }) => {
|
|
|
|
let drawerLockMode = 'unlocked';
|
|
|
|
if (navigation.state.index > 0) {
|
|
|
|
drawerLockMode = 'locked-closed';
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
drawerLockMode
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
const ProfileStack = createStackNavigator({
|
2019-07-17 13:37:20 +00:00
|
|
|
ProfileView: {
|
|
|
|
getScreen: () => require('./views/ProfileView').default
|
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
2019-04-24 18:36:29 +00:00
|
|
|
ProfileStack.navigationOptions = ({ navigation }) => {
|
2019-04-18 13:43:44 +00:00
|
|
|
let drawerLockMode = 'unlocked';
|
|
|
|
if (navigation.state.index > 0) {
|
|
|
|
drawerLockMode = 'locked-closed';
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
drawerLockMode
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
const SettingsStack = createStackNavigator({
|
2019-07-17 13:37:20 +00:00
|
|
|
SettingsView: {
|
|
|
|
getScreen: () => require('./views/SettingsView').default
|
|
|
|
},
|
|
|
|
LanguageView: {
|
|
|
|
getScreen: () => require('./views/LanguageView').default
|
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
2019-05-18 19:31:33 +00:00
|
|
|
const AdminPanelStack = createStackNavigator({
|
2019-07-17 13:37:20 +00:00
|
|
|
AdminPanelView: {
|
|
|
|
getScreen: () => require('./views/AdminPanelView').default
|
|
|
|
}
|
2019-05-18 19:31:33 +00:00
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
2019-04-18 13:43:44 +00:00
|
|
|
SettingsStack.navigationOptions = ({ navigation }) => {
|
|
|
|
let drawerLockMode = 'unlocked';
|
|
|
|
if (navigation.state.index > 0) {
|
|
|
|
drawerLockMode = 'locked-closed';
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
drawerLockMode
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
const ChatsDrawer = createDrawerNavigator({
|
|
|
|
ChatsStack,
|
|
|
|
ProfileStack,
|
2019-05-18 19:31:33 +00:00
|
|
|
SettingsStack,
|
|
|
|
AdminPanelStack
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
2019-09-24 17:37:13 +00:00
|
|
|
contentComponent: Sidebar,
|
|
|
|
overlayColor: '#00000090'
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const NewMessageStack = createStackNavigator({
|
2019-07-17 13:37:20 +00:00
|
|
|
NewMessageView: {
|
|
|
|
getScreen: () => require('./views/NewMessageView').default
|
|
|
|
},
|
|
|
|
SelectedUsersViewCreateChannel: {
|
|
|
|
getScreen: () => require('./views/SelectedUsersView').default
|
|
|
|
},
|
|
|
|
CreateChannelView: {
|
|
|
|
getScreen: () => require('./views/CreateChannelView').default
|
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
}, {
|
|
|
|
defaultNavigationOptions: defaultHeader
|
|
|
|
});
|
|
|
|
|
|
|
|
const InsideStackModal = createStackNavigator({
|
|
|
|
Main: ChatsDrawer,
|
2019-09-25 22:13:39 +00:00
|
|
|
NewMessageStack,
|
|
|
|
JitsiMeetView: {
|
|
|
|
getScreen: () => require('./views/JitsiMeetView').default
|
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
mode: 'modal',
|
|
|
|
headerMode: 'none'
|
|
|
|
});
|
|
|
|
|
|
|
|
const SetUsernameStack = createStackNavigator({
|
2019-07-17 13:37:20 +00:00
|
|
|
SetUsernameView: {
|
|
|
|
getScreen: () => require('./views/SetUsernameView').default
|
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
});
|
|
|
|
|
2019-06-10 16:23:19 +00:00
|
|
|
class CustomInsideStack extends React.Component {
|
|
|
|
static router = InsideStackModal.router;
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
navigation: PropTypes.object
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-06-10 16:23:19 +00:00
|
|
|
<InsideStackModal navigation={navigation} />
|
|
|
|
<NotificationBadge navigation={navigation} />
|
2019-07-23 14:02:57 +00:00
|
|
|
<Toast />
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-06-10 16:23:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-12 16:23:06 +00:00
|
|
|
const App = createAppContainer(createSwitchNavigator(
|
|
|
|
{
|
|
|
|
OutsideStack: OutsideStackModal,
|
2019-06-10 16:23:19 +00:00
|
|
|
InsideStack: CustomInsideStack,
|
2019-07-17 13:37:20 +00:00
|
|
|
AuthLoading: {
|
|
|
|
getScreen: () => require('./views/AuthLoadingView').default
|
|
|
|
},
|
2019-03-12 16:23:06 +00:00
|
|
|
SetUsernameStack
|
|
|
|
},
|
|
|
|
{
|
|
|
|
initialRouteName: 'AuthLoading'
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
2019-03-12 16:23:06 +00:00
|
|
|
));
|
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
export default class Root extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.init();
|
2019-08-23 13:18:47 +00:00
|
|
|
this.initCrashReport();
|
2019-03-18 18:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.listenerTimeout = setTimeout(() => {
|
|
|
|
Linking.addEventListener('url', ({ url }) => {
|
|
|
|
const parsedDeepLinkingURL = parseDeepLinking(url);
|
|
|
|
if (parsedDeepLinkingURL) {
|
|
|
|
store.dispatch(deepLinkingOpen(parsedDeepLinkingURL));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
clearTimeout(this.listenerTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
init = async() => {
|
|
|
|
const [notification, deepLinking] = await Promise.all([initializePushNotifications(), Linking.getInitialURL()]);
|
|
|
|
const parsedDeepLinkingURL = parseDeepLinking(deepLinking);
|
|
|
|
if (notification) {
|
|
|
|
onNotification(notification);
|
|
|
|
} else if (parsedDeepLinkingURL) {
|
|
|
|
store.dispatch(deepLinkingOpen(parsedDeepLinkingURL));
|
|
|
|
} else {
|
|
|
|
store.dispatch(appInit());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-23 13:18:47 +00:00
|
|
|
initCrashReport = () => {
|
|
|
|
RocketChat.getAllowCrashReport()
|
|
|
|
.then((allowCrashReport) => {
|
|
|
|
if (!allowCrashReport) {
|
|
|
|
loggerConfig.autoNotify = false;
|
|
|
|
loggerConfig.registerBeforeSendCallback(() => false);
|
|
|
|
analytics().setAnalyticsCollectionEnabled(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-18 18:52:38 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Provider store={store}>
|
2019-10-30 15:43:57 +00:00
|
|
|
<App
|
|
|
|
ref={(navigatorRef) => {
|
|
|
|
Navigation.setTopLevelNavigator(navigatorRef);
|
|
|
|
}}
|
|
|
|
onNavigationStateChange={onNavigationStateChange}
|
|
|
|
/>
|
2019-03-18 18:52:38 +00:00
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|