* Started with Channel Post List * Added markdown hashtag * Added TouchableWithFeedback component * Added utils/bottom_sheet * Removed BottomSheet in favor of future SlideUpPanel * Added markdown_block_quote * Added markdown_list_item * Added markdown_list * Added MarkDownTableCell component * Markdown_table - in progress - need to verify TS * Added markdown_table * Update Podfile.lock * Added deep_linking constant * Added utils/draft * Update config to include ExperimentalNormalizeMarkdownLinks * Added markdown_link * Added markdown_table_row * Added ProgressiveImage and RetriableImage components and images utils * Converted Retriable component to functional component * Added type definition for commonmark * Continuing with markdown TS * Markdown - Typing props [ in progress ] * Fix boolean flag with mardown block quote * Adding observable config to markdown_link * TS Fixes [ in progress ] * TS fixes * TS fixes - TextStyles * Update markdown.tsx * TS fixes on markdown * TS Fixes - AtMention component * AtMention [ IN PROGRESS ] * Add markdown support * Fix emoji and jumboEmoji on iOS * Fix handleMyTeam operator * Fix navigation style based on theme * Fix iOS MattermostManaged deleteDatabse return error type * wrap setNavigationStackStyles under a requestAnimationFrame * Add preventDoubleTap to channel mention * Increase double tap to 750ms * Fix handleReceivedPostsInChannel chunk query * Set initial navigation theme * Swizzle FastImage on iOS * fix preventDoubleTap test Co-authored-by: Avinash Lingaloo <> Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
162 lines
5.1 KiB
TypeScript
162 lines
5.1 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {Linking} from 'react-native';
|
|
import {Notifications} from 'react-native-notifications';
|
|
|
|
import {Screens} from '@constants';
|
|
import DatabaseManager from '@database/manager';
|
|
import {getActiveServerUrl, getServerCredentials} from '@init/credentials';
|
|
import {queryThemeForCurrentTeam} from '@queries/servers/preference';
|
|
import {goToScreen, resetToChannel, 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;
|
|
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;
|
|
if (database) {
|
|
EphemeralStore.theme = await queryThemeForCurrentTeam(database);
|
|
}
|
|
launchToChannel({...props, serverUrl}, resetNavigation);
|
|
return;
|
|
}
|
|
}
|
|
|
|
launchToServer(props, resetNavigation);
|
|
};
|
|
|
|
const launchToChannel = (props: LaunchProps, resetNavigation: Boolean) => {
|
|
// TODO: Use LaunchProps to fetch posts for channel and then load user profile, etc...
|
|
|
|
const passProps = {
|
|
skipMetrics: true,
|
|
...props,
|
|
};
|
|
|
|
if (resetNavigation) {
|
|
// eslint-disable-next-line no-console
|
|
console.log('Launch app in Channel screen');
|
|
resetToChannel(passProps);
|
|
return;
|
|
}
|
|
|
|
const title = '';
|
|
goToScreen(Screens.CHANNEL, 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;
|
|
};
|