Deeplink: Fix choose parameter (#5237)

This commit is contained in:
zubiden 2024-11-27 20:34:18 +04:00 committed by Alexander Zinchuk
parent 91f7d63297
commit ba9956f921
6 changed files with 31 additions and 31 deletions

View File

@ -20,7 +20,7 @@ import useOldLang from '../../../hooks/useOldLang';
import InfiniteScroll from '../../ui/InfiniteScroll';
import SearchInput from '../../ui/SearchInput';
import WebAppGridItem from './WebAppGridtem';
import WebAppGridItem from './WebAppGridItem';
import styles from './MoreAppsTabContent.module.scss';

View File

@ -32,7 +32,7 @@ import {
TOPICS_SLICE_SECOND_LOAD,
} from '../../../config';
import { copyTextToClipboard } from '../../../util/clipboard';
import { formatShareText, parseChooseParameter, processDeepLink } from '../../../util/deeplink';
import { formatShareText, processDeepLink } from '../../../util/deeplink';
import { isDeepLink } from '../../../util/deepLinkParser';
import { getCurrentTabId } from '../../../util/establishMultitabRole';
import { getOrderedIds } from '../../../util/folderManager';
@ -1282,7 +1282,6 @@ addActionHandler('openTelegramLink', async (global, actions, payload): Promise<v
joinVoiceChatByLink,
focusMessage,
openInvoice,
processAttachBotParameters,
checkChatlistInvite,
openChatByUsername: openChatByUsernameAction,
openStoryViewerByUsername,
@ -1317,9 +1316,6 @@ addActionHandler('openTelegramLink', async (global, actions, payload): Promise<v
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 hasBoost = params.hasOwnProperty('boost');
@ -1432,13 +1428,6 @@ addActionHandler('openTelegramLink', async (global, actions, payload): Promise<v
slug: part2,
tabId,
});
} else if ((hasStartAttach && choose) || (!part2 && hasStartApp)) {
processAttachBotParameters({
username: part1,
filter: choose,
startParam: params.startattach || params.startapp,
tabId,
});
} else if (shouldTryOpenChat) {
openChatByUsernameAction({
username: part1,
@ -1503,7 +1492,7 @@ addActionHandler('acceptChatInvite', async (global, actions, payload): Promise<v
addActionHandler('openChatByUsername', async (global, actions, payload): Promise<void> => {
const {
username, messageId, commentId, startParam, startAttach, attach, threadId, originalParts, startApp,
text, onChatChanged,
text, onChatChanged, choose,
tabId = getCurrentTabId(),
} = payload;
@ -1519,6 +1508,17 @@ addActionHandler('openChatByUsername', async (global, actions, payload): Promise
});
return;
}
if (startAttach !== undefined && choose) {
actions.processAttachBotParameters({
username,
filter: choose,
startParam: startAttach || startApp,
tabId,
});
return;
}
if (startApp !== undefined && !webAppName) {
const theme = extractCurrentThemeParams();
const chatByUsername = await fetchChatByUsername(global, username);

View File

@ -1836,6 +1836,7 @@ export interface ActionPayloads {
startAttach?: string;
attach?: string;
startApp?: string;
choose?: ApiChatType[];
text?: string;
originalParts?: (string | undefined)[];
onChatChanged?: CallbackAction;

View File

@ -65,6 +65,7 @@ interface PublicUsernameOrBotLink {
startAttach?: string;
attach?: string;
text?: string;
choose?: string;
}
interface BusinessChatLink {
@ -202,6 +203,7 @@ function parseTgLink(url: URL) {
startApp: queryParams.startapp,
startAttach: queryParams.startattach,
attach: queryParams.attach,
choose: queryParams.choose,
});
case 'businessChatLink':
return buildBusinessChatLink({ slug: queryParams.slug });
@ -294,6 +296,7 @@ function parseHttpLink(url: URL) {
appName: undefined,
startAttach: queryParams.startattach,
attach: queryParams.attach,
choose: queryParams.choose,
});
case 'businessChatLink':
return buildBusinessChatLink({ slug: pathParams[1] });
@ -523,6 +526,7 @@ function buildPublicUsernameOrBotLink(
startAttach,
attach,
appName,
choose,
} = params;
if (!username) {
return undefined;
@ -539,6 +543,7 @@ function buildPublicUsernameOrBotLink(
startAttach,
attach,
text,
choose,
};
}

View File

@ -17,7 +17,9 @@ export const processDeepLink = (url: string): boolean => {
case 'privateMessageLink':
handlePrivateMessageLink(parsedLink, actions);
return true;
case 'publicUsernameOrBotLink':
case 'publicUsernameOrBotLink': {
const choose = parseChooseParameter(parsedLink.choose);
actions.openChatByUsername({
username: parsedLink.username,
startParam: parsedLink.start,
@ -25,9 +27,11 @@ export const processDeepLink = (url: string): boolean => {
startApp: parsedLink.startApp,
startAttach: parsedLink.startAttach,
attach: parsedLink.attach,
choose,
originalParts: [parsedLink.username, parsedLink.appName],
});
return true;
}
case 'businessChatLink':
actions.resolveBusinessChatLink({
slug: parsedLink.slug,
@ -65,7 +69,6 @@ export const processDeepLink = (url: string): boolean => {
openStickerSet,
joinVoiceChatByLink,
openInvoice,
processAttachBotParameters,
openChatWithDraft,
checkChatlistInvite,
openStoryViewerByUsername,
@ -81,10 +84,7 @@ export const processDeepLink = (url: string): boolean => {
appname, startapp, story, text,
} = params;
const hasStartAttach = params.hasOwnProperty('startattach');
const hasStartApp = params.hasOwnProperty('startapp');
const hasBoost = params.hasOwnProperty('boost');
const choose = parseChooseParameter(params.choose);
const threadId = Number(thread) || Number(topic) || undefined;
if (domain !== 'telegrampassport') {
@ -95,12 +95,6 @@ export const processDeepLink = (url: string): boolean => {
originalParts: [domain, appname],
text,
});
} else if ((hasStartAttach && choose) || (!appname && hasStartApp)) {
processAttachBotParameters({
username: domain,
filter: choose,
startParam: startattach || startapp,
});
} else if (params.hasOwnProperty('voicechat') || params.hasOwnProperty('livestream')) {
joinVoiceChatByLink({
username: domain,
@ -206,12 +200,6 @@ export const processDeepLink = (url: string): boolean => {
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 {
return {
text: [url, title, text].filter(Boolean).join('\n'),
@ -236,3 +224,9 @@ function handlePrivateMessageLink(link: PrivateMessageLink, actions: ReturnType<
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));
}