* Added DrawerItem component * WIP Account Screen * Added react-native-paper * Added StatusLabel Component * Extracted i18n * TS fix DrawerItem component * WIP Account Screen * Added server name label under log out * Updated translation * WIP * Fixes the Offline text style * Added Metropolis fonts * WIP * Typo clean up * WIP * WIP * WIP * Added server display name * Writing OpenSans properly * WIP * WIP * Added OptionsModal * Opening OptionsModal * Added translation keys * Writes status to local db * Fix missing translation * Fix OptionModal not dismissing * Pushing status to server * Refactored * Added CustomStatusExpiry component * Added sub components * Added CustomLabel * CustomStatus WIP * Added Custom Status screen WIP * WIP - unsetCustomStatus and CustomStatus constant * WIP * WIP * WIP * WIP * WIP * WIP * WIP * Retrieving RecentCustomStatuses from Preferences table * WIP * WIP * WIP * Added Clear After Modal * WIP - Transations * WIP * Done with showing modal cst * wip * Clear After Modal - DONE * fix * Added missing API calls * wip * Causing screen refresh * wip * WIP * WIP * WIP * Code clean up * Added OOO alert box * Refactored Options-Item * Refactored OptionsModalList component * Opening 'status' in BottomSheet instead of OptionsModal * AddReaction screen - WIP * Add Reaction screen - WIP * Added EmojiPickerRow * Added @components/emoji_picker - WIP * Emoji Picker - WIP * WIP * WIP * WIP * SectionList - WIP * Installed react-native-section_list_get_item_layout * Adding API calls - WIP * WIP * Search Bar component - WIP * WIP * WIP * WIP * Rendering Emoticons now - have to tackle some fixmes * Code clean up * Code clean up - WIP * Code clean up * WIP * Major clean up * wip * WIP * Fix rendering issue with SectionIcons and SearchBar * Tackled the CustomEmojiPage * Code clean up * WIP * Done with loading User Profiles for Custom Emoji * Code clean up * Code Clean up * Fix screen Account * Added missing sql file for IOS Pod * Updated Podfile.lock * Using queryConfig instead of queryCommonSystemValues * Fix - Custom status * Fix - Custom Status - Error * Fix - Clear Pass Status - WIP * Fix - Custom Status Clear * Need to fix CST clear * WIP * Status clear - working * Using catchError operator * remove unnecessary prop * Status BottomSheet now has colored indicators * Added KeyboardTrackingView from 'react-native-keyboard-tracking-view' * Code clean up * WIP * code clean up * Added a safety check * Fix - Display suggestions * Code clean up based on PR Review * Code clean up * Code clean up * Code clean up * Corrections * Fix tsc * TS fix * Removed unnecessary prop * Fix SearchBar Ts * Updated tests * Delete search_bar.test.js.snap * Merge branch 'gekidou' into gekidou_account_screen * Revert "Merge branch 'gekidou' into gekidou_account_screen" This reverts commit 5defc313212478a55abf2f92cb4bd64dc7877342. * Fix fonts * Refactor home account screen * fix theme provider * refactor bottom sheet * remove paper provider * update drawer item snapshots * Remove options modal screen * remove react-native-ui-lib dependency * Refactor & fix custom status & navigation (including tablet) * Refactor emoji picker Co-authored-by: Avinash Lingaloo <> Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
202 lines
6.7 KiB
TypeScript
202 lines
6.7 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import Emm from '@mattermost/react-native-emm';
|
|
import {Alert, Linking} from 'react-native';
|
|
import {Notifications} from 'react-native-notifications';
|
|
|
|
import {appEntry, upgradeEntry} from '@actions/remote/entry';
|
|
import {Screens} from '@constants';
|
|
import DatabaseManager from '@database/manager';
|
|
import {getActiveServerUrl, getServerCredentials, removeServerCredentials} from '@init/credentials';
|
|
import {queryThemeForCurrentTeam} from '@queries/servers/preference';
|
|
import {queryCurrentUserId} from '@queries/servers/system';
|
|
import {goToScreen, resetToHome, resetToSelectServer} from '@screens/navigation';
|
|
import EphemeralStore from '@store/ephemeral_store';
|
|
import {DeepLinkChannel, DeepLinkDM, DeepLinkGM, DeepLinkPermalink, DeepLinkType, DeepLinkWithData, LaunchProps, LaunchType} from '@typings/launch';
|
|
import {parseDeepLink} from '@utils/url';
|
|
|
|
export const initialLaunch = async () => {
|
|
const deepLinkUrl = await Linking.getInitialURL();
|
|
if (deepLinkUrl) {
|
|
launchAppFromDeepLink(deepLinkUrl);
|
|
return;
|
|
}
|
|
|
|
const notification = await Notifications.getInitialNotification();
|
|
if (notification && notification.payload?.type === 'message') {
|
|
launchAppFromNotification(notification);
|
|
return;
|
|
}
|
|
|
|
launchApp({launchType: LaunchType.Normal});
|
|
};
|
|
|
|
const launchAppFromDeepLink = (deepLinkUrl: string) => {
|
|
const props = getLaunchPropsFromDeepLink(deepLinkUrl);
|
|
launchApp(props);
|
|
};
|
|
|
|
const launchAppFromNotification = (notification: NotificationWithData) => {
|
|
const props = getLaunchPropsFromNotification(notification);
|
|
launchApp(props);
|
|
};
|
|
|
|
const launchApp = async (props: LaunchProps, resetNavigation = true) => {
|
|
let serverUrl: string | undefined;
|
|
switch (props?.launchType) {
|
|
case LaunchType.DeepLink:
|
|
if (props.extra?.type !== DeepLinkType.Invalid) {
|
|
const extra = props.extra as DeepLinkWithData;
|
|
serverUrl = extra.data?.serverUrl;
|
|
}
|
|
break;
|
|
case LaunchType.Notification: {
|
|
const extra = props.extra as NotificationWithData;
|
|
serverUrl = extra.payload?.server_url;
|
|
break;
|
|
}
|
|
default:
|
|
serverUrl = await getActiveServerUrl();
|
|
break;
|
|
}
|
|
|
|
if (props.launchError && !serverUrl) {
|
|
serverUrl = await getActiveServerUrl();
|
|
}
|
|
|
|
if (serverUrl) {
|
|
const credentials = await getServerCredentials(serverUrl);
|
|
if (credentials) {
|
|
const database = DatabaseManager.serverDatabases[serverUrl]?.database;
|
|
let hasCurrentUser = false;
|
|
if (database) {
|
|
EphemeralStore.theme = await queryThemeForCurrentTeam(database);
|
|
const currentUserId = await queryCurrentUserId(database);
|
|
hasCurrentUser = Boolean(currentUserId);
|
|
}
|
|
|
|
if (!hasCurrentUser) {
|
|
// migrating from v1
|
|
const result = await upgradeEntry(serverUrl);
|
|
if (result.error) {
|
|
Alert.alert(
|
|
'Error Upgrading',
|
|
`An error ocurred while upgrading the app to the new version.\n\nDetails: ${result.error}\n\nThe app will now quit.`,
|
|
[{
|
|
text: 'OK',
|
|
onPress: async () => {
|
|
await DatabaseManager.destroyServerDatabase(serverUrl!);
|
|
await removeServerCredentials(serverUrl!);
|
|
Emm.exitApp();
|
|
},
|
|
}],
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
|
|
launchToHome({...props, launchType: hasCurrentUser ? LaunchType.Normal : LaunchType.Upgrade, serverUrl}, resetNavigation);
|
|
return;
|
|
}
|
|
}
|
|
|
|
launchToServer(props, resetNavigation);
|
|
};
|
|
|
|
const launchToHome = (props: LaunchProps, resetNavigation: Boolean) => {
|
|
switch (props.launchType) {
|
|
case LaunchType.DeepLink:
|
|
// TODO:
|
|
// deepLinkEntry({props.serverUrl, props.extra});
|
|
break;
|
|
case LaunchType.Notification: {
|
|
// TODO:
|
|
// pushNotificationEntry({props.serverUrl, props.extra})
|
|
break;
|
|
}
|
|
case LaunchType.Normal:
|
|
appEntry(props.serverUrl!);
|
|
break;
|
|
}
|
|
|
|
const passProps = {
|
|
skipMetrics: true,
|
|
...props,
|
|
};
|
|
|
|
if (resetNavigation) {
|
|
// eslint-disable-next-line no-console
|
|
console.log('Launch app in Home screen');
|
|
resetToHome(passProps);
|
|
return;
|
|
}
|
|
|
|
const title = '';
|
|
goToScreen(Screens.HOME, title, passProps);
|
|
};
|
|
|
|
const launchToServer = (props: LaunchProps, resetNavigation: Boolean) => {
|
|
if (resetNavigation) {
|
|
resetToSelectServer(props);
|
|
return;
|
|
}
|
|
|
|
const title = '';
|
|
goToScreen(Screens.SERVER, title, {...props});
|
|
};
|
|
|
|
export const relaunchApp = (props: LaunchProps, resetNavigation = false) => {
|
|
launchApp(props, resetNavigation);
|
|
};
|
|
|
|
export const getLaunchPropsFromDeepLink = (deepLinkUrl: string): LaunchProps => {
|
|
const parsed = parseDeepLink(deepLinkUrl);
|
|
const launchProps: LaunchProps = {
|
|
launchType: LaunchType.DeepLink,
|
|
};
|
|
|
|
switch (parsed.type) {
|
|
case DeepLinkType.Invalid:
|
|
launchProps.launchError = true;
|
|
break;
|
|
case DeepLinkType.Channel: {
|
|
const parsedData = parsed.data as DeepLinkChannel;
|
|
(launchProps.extra as DeepLinkWithData).data = parsedData;
|
|
break;
|
|
}
|
|
case DeepLinkType.DirectMessage: {
|
|
const parsedData = parsed.data as DeepLinkDM;
|
|
(launchProps.extra as DeepLinkWithData).data = parsedData;
|
|
break;
|
|
}
|
|
case DeepLinkType.GroupMessage: {
|
|
const parsedData = parsed.data as DeepLinkGM;
|
|
(launchProps.extra as DeepLinkWithData).data = parsedData;
|
|
break;
|
|
}
|
|
case DeepLinkType.Permalink: {
|
|
const parsedData = parsed.data as DeepLinkPermalink;
|
|
(launchProps.extra as DeepLinkWithData).data = parsedData;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return launchProps;
|
|
};
|
|
|
|
export const getLaunchPropsFromNotification = (notification: NotificationWithData): LaunchProps => {
|
|
const {payload} = notification;
|
|
|
|
const launchProps: LaunchProps = {
|
|
launchType: LaunchType.Notification,
|
|
};
|
|
|
|
if (payload?.server_url) {
|
|
(launchProps.extra as NotificationWithData) = notification;
|
|
} else {
|
|
launchProps.launchError = true;
|
|
}
|
|
|
|
return launchProps;
|
|
};
|