Deeplink: Fix choose parameter (#5237)
This commit is contained in:
parent
91f7d63297
commit
ba9956f921
@ -20,7 +20,7 @@ import useOldLang from '../../../hooks/useOldLang';
|
|||||||
|
|
||||||
import InfiniteScroll from '../../ui/InfiniteScroll';
|
import InfiniteScroll from '../../ui/InfiniteScroll';
|
||||||
import SearchInput from '../../ui/SearchInput';
|
import SearchInput from '../../ui/SearchInput';
|
||||||
import WebAppGridItem from './WebAppGridtem';
|
import WebAppGridItem from './WebAppGridItem';
|
||||||
|
|
||||||
import styles from './MoreAppsTabContent.module.scss';
|
import styles from './MoreAppsTabContent.module.scss';
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import {
|
|||||||
TOPICS_SLICE_SECOND_LOAD,
|
TOPICS_SLICE_SECOND_LOAD,
|
||||||
} from '../../../config';
|
} from '../../../config';
|
||||||
import { copyTextToClipboard } from '../../../util/clipboard';
|
import { copyTextToClipboard } from '../../../util/clipboard';
|
||||||
import { formatShareText, parseChooseParameter, processDeepLink } from '../../../util/deeplink';
|
import { formatShareText, processDeepLink } from '../../../util/deeplink';
|
||||||
import { isDeepLink } from '../../../util/deepLinkParser';
|
import { isDeepLink } from '../../../util/deepLinkParser';
|
||||||
import { getCurrentTabId } from '../../../util/establishMultitabRole';
|
import { getCurrentTabId } from '../../../util/establishMultitabRole';
|
||||||
import { getOrderedIds } from '../../../util/folderManager';
|
import { getOrderedIds } from '../../../util/folderManager';
|
||||||
@ -1282,7 +1282,6 @@ addActionHandler('openTelegramLink', async (global, actions, payload): Promise<v
|
|||||||
joinVoiceChatByLink,
|
joinVoiceChatByLink,
|
||||||
focusMessage,
|
focusMessage,
|
||||||
openInvoice,
|
openInvoice,
|
||||||
processAttachBotParameters,
|
|
||||||
checkChatlistInvite,
|
checkChatlistInvite,
|
||||||
openChatByUsername: openChatByUsernameAction,
|
openChatByUsername: openChatByUsernameAction,
|
||||||
openStoryViewerByUsername,
|
openStoryViewerByUsername,
|
||||||
@ -1317,9 +1316,6 @@ addActionHandler('openTelegramLink', async (global, actions, payload): Promise<v
|
|||||||
hash = part2;
|
hash = part2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasStartAttach = params.hasOwnProperty('startattach');
|
|
||||||
const hasStartApp = params.hasOwnProperty('startapp');
|
|
||||||
const choose = parseChooseParameter(params.choose);
|
|
||||||
const storyId = part2 === 's' && (Number(part3) || undefined);
|
const storyId = part2 === 's' && (Number(part3) || undefined);
|
||||||
const hasBoost = params.hasOwnProperty('boost');
|
const hasBoost = params.hasOwnProperty('boost');
|
||||||
|
|
||||||
@ -1432,13 +1428,6 @@ addActionHandler('openTelegramLink', async (global, actions, payload): Promise<v
|
|||||||
slug: part2,
|
slug: part2,
|
||||||
tabId,
|
tabId,
|
||||||
});
|
});
|
||||||
} else if ((hasStartAttach && choose) || (!part2 && hasStartApp)) {
|
|
||||||
processAttachBotParameters({
|
|
||||||
username: part1,
|
|
||||||
filter: choose,
|
|
||||||
startParam: params.startattach || params.startapp,
|
|
||||||
tabId,
|
|
||||||
});
|
|
||||||
} else if (shouldTryOpenChat) {
|
} else if (shouldTryOpenChat) {
|
||||||
openChatByUsernameAction({
|
openChatByUsernameAction({
|
||||||
username: part1,
|
username: part1,
|
||||||
@ -1503,7 +1492,7 @@ addActionHandler('acceptChatInvite', async (global, actions, payload): Promise<v
|
|||||||
addActionHandler('openChatByUsername', async (global, actions, payload): Promise<void> => {
|
addActionHandler('openChatByUsername', async (global, actions, payload): Promise<void> => {
|
||||||
const {
|
const {
|
||||||
username, messageId, commentId, startParam, startAttach, attach, threadId, originalParts, startApp,
|
username, messageId, commentId, startParam, startAttach, attach, threadId, originalParts, startApp,
|
||||||
text, onChatChanged,
|
text, onChatChanged, choose,
|
||||||
tabId = getCurrentTabId(),
|
tabId = getCurrentTabId(),
|
||||||
} = payload;
|
} = payload;
|
||||||
|
|
||||||
@ -1519,6 +1508,17 @@ addActionHandler('openChatByUsername', async (global, actions, payload): Promise
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (startAttach !== undefined && choose) {
|
||||||
|
actions.processAttachBotParameters({
|
||||||
|
username,
|
||||||
|
filter: choose,
|
||||||
|
startParam: startAttach || startApp,
|
||||||
|
tabId,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (startApp !== undefined && !webAppName) {
|
if (startApp !== undefined && !webAppName) {
|
||||||
const theme = extractCurrentThemeParams();
|
const theme = extractCurrentThemeParams();
|
||||||
const chatByUsername = await fetchChatByUsername(global, username);
|
const chatByUsername = await fetchChatByUsername(global, username);
|
||||||
|
|||||||
@ -1836,6 +1836,7 @@ export interface ActionPayloads {
|
|||||||
startAttach?: string;
|
startAttach?: string;
|
||||||
attach?: string;
|
attach?: string;
|
||||||
startApp?: string;
|
startApp?: string;
|
||||||
|
choose?: ApiChatType[];
|
||||||
text?: string;
|
text?: string;
|
||||||
originalParts?: (string | undefined)[];
|
originalParts?: (string | undefined)[];
|
||||||
onChatChanged?: CallbackAction;
|
onChatChanged?: CallbackAction;
|
||||||
|
|||||||
@ -65,6 +65,7 @@ interface PublicUsernameOrBotLink {
|
|||||||
startAttach?: string;
|
startAttach?: string;
|
||||||
attach?: string;
|
attach?: string;
|
||||||
text?: string;
|
text?: string;
|
||||||
|
choose?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BusinessChatLink {
|
interface BusinessChatLink {
|
||||||
@ -202,6 +203,7 @@ function parseTgLink(url: URL) {
|
|||||||
startApp: queryParams.startapp,
|
startApp: queryParams.startapp,
|
||||||
startAttach: queryParams.startattach,
|
startAttach: queryParams.startattach,
|
||||||
attach: queryParams.attach,
|
attach: queryParams.attach,
|
||||||
|
choose: queryParams.choose,
|
||||||
});
|
});
|
||||||
case 'businessChatLink':
|
case 'businessChatLink':
|
||||||
return buildBusinessChatLink({ slug: queryParams.slug });
|
return buildBusinessChatLink({ slug: queryParams.slug });
|
||||||
@ -294,6 +296,7 @@ function parseHttpLink(url: URL) {
|
|||||||
appName: undefined,
|
appName: undefined,
|
||||||
startAttach: queryParams.startattach,
|
startAttach: queryParams.startattach,
|
||||||
attach: queryParams.attach,
|
attach: queryParams.attach,
|
||||||
|
choose: queryParams.choose,
|
||||||
});
|
});
|
||||||
case 'businessChatLink':
|
case 'businessChatLink':
|
||||||
return buildBusinessChatLink({ slug: pathParams[1] });
|
return buildBusinessChatLink({ slug: pathParams[1] });
|
||||||
@ -523,6 +526,7 @@ function buildPublicUsernameOrBotLink(
|
|||||||
startAttach,
|
startAttach,
|
||||||
attach,
|
attach,
|
||||||
appName,
|
appName,
|
||||||
|
choose,
|
||||||
} = params;
|
} = params;
|
||||||
if (!username) {
|
if (!username) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -539,6 +543,7 @@ function buildPublicUsernameOrBotLink(
|
|||||||
startAttach,
|
startAttach,
|
||||||
attach,
|
attach,
|
||||||
text,
|
text,
|
||||||
|
choose,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,9 @@ export const processDeepLink = (url: string): boolean => {
|
|||||||
case 'privateMessageLink':
|
case 'privateMessageLink':
|
||||||
handlePrivateMessageLink(parsedLink, actions);
|
handlePrivateMessageLink(parsedLink, actions);
|
||||||
return true;
|
return true;
|
||||||
case 'publicUsernameOrBotLink':
|
case 'publicUsernameOrBotLink': {
|
||||||
|
const choose = parseChooseParameter(parsedLink.choose);
|
||||||
|
|
||||||
actions.openChatByUsername({
|
actions.openChatByUsername({
|
||||||
username: parsedLink.username,
|
username: parsedLink.username,
|
||||||
startParam: parsedLink.start,
|
startParam: parsedLink.start,
|
||||||
@ -25,9 +27,11 @@ export const processDeepLink = (url: string): boolean => {
|
|||||||
startApp: parsedLink.startApp,
|
startApp: parsedLink.startApp,
|
||||||
startAttach: parsedLink.startAttach,
|
startAttach: parsedLink.startAttach,
|
||||||
attach: parsedLink.attach,
|
attach: parsedLink.attach,
|
||||||
|
choose,
|
||||||
originalParts: [parsedLink.username, parsedLink.appName],
|
originalParts: [parsedLink.username, parsedLink.appName],
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
case 'businessChatLink':
|
case 'businessChatLink':
|
||||||
actions.resolveBusinessChatLink({
|
actions.resolveBusinessChatLink({
|
||||||
slug: parsedLink.slug,
|
slug: parsedLink.slug,
|
||||||
@ -65,7 +69,6 @@ export const processDeepLink = (url: string): boolean => {
|
|||||||
openStickerSet,
|
openStickerSet,
|
||||||
joinVoiceChatByLink,
|
joinVoiceChatByLink,
|
||||||
openInvoice,
|
openInvoice,
|
||||||
processAttachBotParameters,
|
|
||||||
openChatWithDraft,
|
openChatWithDraft,
|
||||||
checkChatlistInvite,
|
checkChatlistInvite,
|
||||||
openStoryViewerByUsername,
|
openStoryViewerByUsername,
|
||||||
@ -81,10 +84,7 @@ export const processDeepLink = (url: string): boolean => {
|
|||||||
appname, startapp, story, text,
|
appname, startapp, story, text,
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
const hasStartAttach = params.hasOwnProperty('startattach');
|
|
||||||
const hasStartApp = params.hasOwnProperty('startapp');
|
|
||||||
const hasBoost = params.hasOwnProperty('boost');
|
const hasBoost = params.hasOwnProperty('boost');
|
||||||
const choose = parseChooseParameter(params.choose);
|
|
||||||
const threadId = Number(thread) || Number(topic) || undefined;
|
const threadId = Number(thread) || Number(topic) || undefined;
|
||||||
|
|
||||||
if (domain !== 'telegrampassport') {
|
if (domain !== 'telegrampassport') {
|
||||||
@ -95,12 +95,6 @@ export const processDeepLink = (url: string): boolean => {
|
|||||||
originalParts: [domain, appname],
|
originalParts: [domain, appname],
|
||||||
text,
|
text,
|
||||||
});
|
});
|
||||||
} else if ((hasStartAttach && choose) || (!appname && hasStartApp)) {
|
|
||||||
processAttachBotParameters({
|
|
||||||
username: domain,
|
|
||||||
filter: choose,
|
|
||||||
startParam: startattach || startapp,
|
|
||||||
});
|
|
||||||
} else if (params.hasOwnProperty('voicechat') || params.hasOwnProperty('livestream')) {
|
} else if (params.hasOwnProperty('voicechat') || params.hasOwnProperty('livestream')) {
|
||||||
joinVoiceChatByLink({
|
joinVoiceChatByLink({
|
||||||
username: domain,
|
username: domain,
|
||||||
@ -206,12 +200,6 @@ export const processDeepLink = (url: string): boolean => {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function parseChooseParameter(choose?: string) {
|
|
||||||
if (!choose) return undefined;
|
|
||||||
const types = choose.toLowerCase().split(' ');
|
|
||||||
return types.filter((type): type is ApiChatType => API_CHAT_TYPES.includes(type as ApiChatType));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatShareText(url?: string, text?: string, title?: string): ApiFormattedText {
|
export function formatShareText(url?: string, text?: string, title?: string): ApiFormattedText {
|
||||||
return {
|
return {
|
||||||
text: [url, title, text].filter(Boolean).join('\n'),
|
text: [url, title, text].filter(Boolean).join('\n'),
|
||||||
@ -236,3 +224,9 @@ function handlePrivateMessageLink(link: PrivateMessageLink, actions: ReturnType<
|
|||||||
messageId,
|
messageId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseChooseParameter(choose?: string) {
|
||||||
|
if (!choose) return undefined;
|
||||||
|
const types = choose.toLowerCase().split(' ');
|
||||||
|
return types.filter((type): type is ApiChatType => API_CHAT_TYPES.includes(type as ApiChatType));
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user